stephenmp
asked on
Javascript submit on enter error
Ok... Hopefully a simple fix... I use this script to allow users to submit their search forms when they hit the enter key in the zip code field... The problem I'm having is that if they have autocomplete on, and they type 43 and then the autocomplete shows 43123 under the field and the user clicks it and hits enter... When it submits the search, it only registers the "43". The autocomplete works fine without my script, but then it only submits if they hit submit...
Thanks...
Thanks...
onKeyPress="return submitenter(this,event)"
<SCRIPT TYPE="text/javascript">
<!--
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13)
{
formMyForm = document.getElementById("home_search_form");
formMyForm.action = "vehicle_search.php";
formMyForm.submit();
}
else
return true;
}
//-->
</SCRIPT>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's more a validator... I can do that with jquery... I'm looking to move the onkeypress to something that will only call on enter when the autocomplete enter has been pushed...
Else try a timer :
<SCRIPT TYPE="text/javascript">
<!--
function submitenter(myfield,e) {
var keycode = (window.event)?(window.event.keyCode):(e.which);
if(keycode == 13) setTimeout("afterHalf()", 500);
return true;
}
function afterHalf() {
formMyForm = document.getElementById("home_search_form");
formMyForm.action = "vehicle_search.php";
formMyForm.submit();
}
//-->
</SCRIPT>
Thanks for the points!
ASKER
Thank you...
You're very welcome!
if (myfield.length < 5) return false;
user will need to enter again to submit