View Full Version : Form not posting on clicking enter on keyboard

06-01-2009, 07:57 PM
I have not been codeing for too long. The form submits correctly when the button is pressed bu wheni click enter on keyboard it gives a page not foud error

here is the code

function ByPartNo(){
var strTest = document.form1.search_criteria.value;
if (strTest){
document.form1.action="result_details_by_part_no.asp?mSKU="+ strTest
alert("Please Enter a Valid ID.")

<form id="form1" name="form1" method="post">
<input name="search_criteria" type="text" id="search_criteria" size="25" /></td>
<td width="42%" style="border-style: none; border-width: medium">&nbsp;<a href="javascript:ByPartNo()"><img src="images/search_button.gif" width="105" height="26" border="0" /></a></td>

Any help would be appreciated. Thanks in advance

06-01-2009, 08:15 PM
For a form to submit on hitting enter, you'd need form action to be present, rather than being set via JavaScript. Otherwise, you're going to need an event handler in every field that will monitor for the enter key and if it fires, execute the JS function you have. You could always re-name the search_criteria field to mSKU instead and get rid of the JS completely, adding a form action of the web-page you need to post your information to. Otherwise... you're not really doing a POST with your code, it's more doing a POST to a web-page which has the GET variables pre-filled.