JavaScript redirect not working with enter key


I have a script that submits a bid and currently have it working when pressing the submit button or pressing the enter key. Everything works perfectly while pressing the button, but it works halfway when pressing the enter key.

When I press the enter key, the proper information gets validated, the alert window pops up as normal, information passes, but it won’t redirect using:

document.location = url;

When using the enter key, everything in the script works (validation and everything), it just won’t redirect. It’s strange.

Please let me know why this isn’t working.

Kind regards

EDIT: I also tried to add the following javascript code into the bidding text box where the price gets entered:

onkeydown="if (event.keyCode == 13) document.getElementById('bidsubmit').click();"

This makes the JavaScript validation happen twice if I hit that enter key.

Nevermind, I figured it out sorta…

Seems like clicking the button (<input type=“button” onclick=“validate();” />) field made the onclick() function work properly and redirected to the final URL that was given in the validation script.

Pressing the enter key triggered a click on the <input type=“button” onclick=“validate();” /> button and went through the validation, but redirected to the <form action=“URL”> instead of the URL given at the end of the validation script.

I removed the <form></form> tags and just left <input> fields instead. Seems to validate W3C correctly and work correctly in every way now.

Thanks for looking.

Kind regards

don’t know what the page looks like, but you don’t need to remove form tags. You can just remove the action and, if needed, place it wthin the validation function:

<input type=“button” onclick=“doValidate(this.form)”>

function doValidate(formObj) {
var ok2Send = true;
…validation code that set above var to false if failure
if (ok2Send) {
formObj.action = “dkdkdkk”;
formObj.method = “,d,d,”