I am trying to prevent a submit event on a page using this code so that if I will press enter it will click the validate
element.
$(document).ready(function(){
$("form").submit(function(event){
event.preventDefault();
document.getElementById("validate").click();//alert("Something") works fine here
});
});
But,when I pressed enter keeping the focus on any text field it submits the form with the action assigned to the form.It is not preventing the Submit
event as expected in google chrome 47. If I will place any alert
rather than document.getElementById("validate").click();
then it works fine. Here is the html code for that page
<td align="center" width="100%">
<input type="button" value=" Next " id="validate" tabindex="4">
<a id="Proceed" href="#" onclick="mojarra.jsfcljs(document.getElementById('form'),{'Form:Proceed':'Form:Proceed'},'');return false"></a>
<input id="replan" type="submit" name="replan" value="Replan" tabindex="4">
</td>
So, Can anyone please explain why this is not working in newer version of chrome?(It is working fine in chrome 39)
Note: The event to id validate
is assigned using addEventListener()
.