Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Thanked 0 Times in 0 Posts

    Form not posting on clicking enter on keyboard

    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

  2. #2
    Regular Coder
    Join Date
    Feb 2009
    Wheeling, IL
    Thanked 62 Times in 60 Posts
    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.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts