I have an html form which runs a javascript function before submitting. The html of the form tag is:
<form onsubmit="return sub();" method="post" action="useclick.php">
The html of the submit button is:
<input type="submit" value="Submit" id="submit"/>
That all works fine, but I want the user to be able to press enter anywhere and for it to submit the form so I've got this bit of code:
$(document).keypress(function(e) {
if(e.which == 13) {
$(this).blur();
$('#submit').focus().click();
}
});
This does exactly what I want in all browser except IE. In IE, it does click the submit button, and send off the form but it doesn't run the sub() function first. It's the same in IE 8 and 10, which are the only versions I have access to at the moment.
For completeness, the sub() function looks like:
function sub(){
document.getElementsByName('coords')[0].value = JSON.stringify(coordsArray);
return true;
}
I'm fairly new to javascript and very new to jQuery so any help would be very useful.
coordselement. only as an attribute of maparea.submitevent of the form instead.coordsis the name of an input:<input type="hidden" name="coords" />getElementsByTagName. sorry.