I would like to include only certain form fields when submitting a form with jQuery. For instance, I would like to ignore all fields that have the disabled
attribute... maybe something like this:
$('#my_button').click(function() {
if($('input').hasAttr('disabled') {
//ignore this form field when submitting
}
$('form').submit();
});
Any ideas?
$(document). on('keyup keypress', 'form input[type="text"]', function(e) { if(e. keyCode == 13) { e. preventDefault(); return false; } });
One of the most used logic related to submitting a form is preventing sumbission if a field is empty. In this example we'll provide examples with source code how to prevent form submit in case of empty field. The main trick here is using . preventDefault() function to stop the submission.
You can use e. preventDefault() or return false; within a jQuery event handler: $("#Formid").
Use preventDefault() event method to Prevent form submission on the “Enter” key pressed in JavaScript. Enter key keycode is 13, so you can check in if statement.
That's not necessary, disabled
inputs are excluded already. The various jQuery methods, including submit() and serialize() honour the HTML 4 specification for disabled controls in web forms, which goes as follows:
A successful control is "valid" for submission. Every successful control has its control name paired with its current value as part of the submitted form data set. A successful control must be defined within a FORM element and must have a control name.
However:
- Controls that are
disabled
cannot be successful.
http://www.w3.org/TR/html401/interact/forms.html#successful-controls
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