I have this HTML:
<input type="text" name="textField" /> <input type="submit" value="send" />
How can I do something like this:
I tried something like this:
$(document).ready(function(){ $('input[type="submit"]').attr('disabled','disabled'); $('input[type="text"]').change(function(){ if($(this).val != ''){ $('input[type="submit"]').removeAttr('disabled'); } }); });
…but it doesn't work. Any ideas?
click(function () { if ($('#submit-button').is(':disabled')) { $('#submit-button'). removeAttr('disabled'); } else { $('#submit-button'). attr('disabled', 'disabled'); } }); In the above code, enabled is the id of the checkbox used and submit-button is the class name of the submit button used .
Checking if the button is disabled or enabled with jQuery removeAttr('disabled'); }; const checkButton = (e) => { const isDisabled = $('#my-button'). prop('disabled'); if( isDisabled ){ alert("Is disabled!"); } else{ alert("Is enabled"); } }; $(document).
Just click f12 in your browser, find the submit button in the html, and then remove the disabled ! It will submit the form even if the inputs are empty.
The problem is that the change event fires only when focus is moved away from the input (e.g. someone clicks off the input or tabs out of it). Try using keyup instead:
$(document).ready(function() { $(':input[type="submit"]').prop('disabled', true); $('input[type="text"]').keyup(function() { if($(this).val() != '') { $(':input[type="submit"]').prop('disabled', false); } }); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With