0

Here is my code. The problem I encountered is how do I make the submit button work only when it is 10?

<input type="text" name="qty>
<input type="submit" name="proceedbtn" value="PROCEED" id="button">

<script>
   $(document).ready(function(){
        $('input[id="button"]').attr('disabled',true);
        $('input[id="qty"]').on('keyup',function(){
            if($(this).val() == 10)
            $('input[id="button"]').attr('disabled',false);
    });
});
</script>

How do i fix it?

2
  • What's the error you have faced? Commented Feb 20, 2020 at 6:55
  • you don't have any input with id qty in your html. That is the only issue I see. Commented Feb 20, 2020 at 6:59

3 Answers 3

1

I have made some corrections in your code, and now its working. The problem in your code was, you were writing key up event on ID but haven't assigned any id to input box, but you had name property so instead of id I used that name property as a selector for key up event.

$(document).ready(function() {
  $('input[id="button"]').attr('disabled', true);
  $('input[name="qty"]').on('keyup', function() {
    if ($(this).val() == 10) {
      $('input[id="button"]').attr('disabled', false);
    } else {
      $('input[id="button"]').attr('disabled', true);
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" value="" name="qty" />
<input type="submit" name="proceedbtn" value="PROCEED" id="button" />

Sign up to request clarification or add additional context in comments.

Comments

1

Please check, I have updated your code

  $(document).ready(function(){
        $('input[id="button"]').attr('disabled',true);
        $('input[name="qty"]').keyup(function(){
            if($(this).val() == 10){
            $('input[id="button"]').removeAttr('disabled');
            }
            else{
              $('input[id="button"]').attr('disabled',true);
            }
    });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" name="qty">
<input type="submit" name="proceedbtn" value="PROCEED" id="button">

Comments

1

I have made some editions on your code and IT WORKS PERFECTLY!

$(document).ready(function() {
        $('#button').attr('disabled', true);
        $('input[name="qty"]').on('keyup', function () {
            if ($(this).val() == 10) {
                $('#button').attr('disabled', false);
            }else {
                $('#button').attr('disabled', true);
            }
        });
    });
<input type="text" name="qty">
<input type="submit" name="proceedbtn" value="PROCEED" id="button">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.