I create three input fields which is a,b & c . a is a numeric input field and b & c are hidden input field and the c have a static value. a generating b input field's value something like when you input 1 on a, b value turn into 10, if you input 2 it generate b value=20 which is b.val()= a.val()*10 it's working fine . But I want to prevent the submit button when user don't type on a and input result b.val() cross the c.val() . I write a code but it's not working . Is I messing something? I can't see any error on console . Please suggest me :
$('#m-submit').prop('disabled',true);
var ainput= $('#a').keyup();
var binput= $('#c').val() >= $('#b').val();
if (ainput && binput) {
$('#m-submit').prop('disabled', this.value == "" ? true : false);
}
<input type='number' name='a' id='a' />
<input type='hidden' value='' name='b' id='b' />
<input type='hidden' value='100' name='c' id='c' />
<button id='m-submit'>Submit</button>
var ainput= $('#a').keyup();Why are you triggering a keyup event manually? Did you mean to try and handle this event? I'm also not certain that it will return a value to put intoainput. Your code seems out of context. If someone took this code exactly as it is, it would never work because the code is seemingly running before the user can input anything. I presume this is just some small parts of your real code. Some context would be useful as to when this code is actually getting executed.