I am using ajax functionality. When i am selecting any suggestion using enter key, the form get submitted automatically because the submit button is auto-focused. Is there any way to select ajax suggestion using enter key as well submit the form using enter key. Something like when i input the values of all the fields then only submit button get enabled.
addEventListener("submit",function(e){e. preventDefault(); return false;}); This solution will now prevent the user from submit using the enter Key and will not reload the page, or take you to the top of the page, if your form is somewhere below.
To submit a form without Ajax, you can either disable Ajax form handling globally, or per form via the data-ajax="false" attribute. The target attribute (as in target="_blank" ) is respected on forms as well, and will default to the browser's handling of that target when the form submits.
Disallow enter key anywhere$(document). on("keydown", "form", function(event) { return event. key != "Enter"; });
1.1 To disable a submit button, you just need to add a disabled attribute to the submit button. $("#btnSubmit"). attr("disabled", true); 1.2 To enable a disabled button, set the disabled attribute to false, or remove the disabled attribute.
How are you calling your Ajax function? It should be inside the submit
event handler of the form. And then if you have the event handler return false
it won't submit normally:
<form onsubmit="doAjaxSubmit(); return false;">
...
</form>
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