SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question submit on enter ?

    in a typical form when you hit the enter key it will submit the data, however I am not using a submit button but rather a regular button the calls this funtion:

    Code:
     
    function submitDB(){
    var itemnum = document.formhandheld.itemnum.value;
    var readSource = 0;
    var readType = 0; 
    window.location.href = "PocketPCDetails.asp?ScanCheck=1&itemnum=" + itemnum + "&readSource=" + readSource + "&readType=" + readType;  
    }
    I would still like the enter key to submit or call this function. HELP!

  2. #2
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    add an onSubmit(submitDB); to the button?

  3. #3
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually, it's this (i think) in the action portion of the form:

    onSubmit="submitDB();"

  4. #4
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did this work? I'm really interested in this.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  5. #5
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm, not sure I get that, like action="submitDB()" ??

    and then do I change the button to be a submit button

  6. #6
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I cant seem to get it

  7. #7
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can we see the relevant code?

  8. #8
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's what I have:
    Code:
    function submitDB(){
    var itemnum = document.formhandheld.itemnum.value;
    var readSource = 0;
    var readType = 0; 
    window.location.href = "PocketPCDetails.asp?ScanCheck=1&itemnum=" + itemnum + "&readSource=" + readSource + "&readType=" + readType; 
    }
    Code:
     
    <form method="get" name="formhandheld">
    Code:
     
    <input type="button" name="Details" value="&nbsp;Details&nbsp;" onClick="submitDB()">
    FYI, the code works, but I cant use the ENTER key, need that

  9. #9
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the enter key probably has to do with it not being a submit button(?). hmmmmm... any reason why it can't be a submit button?

  10. #10
    Freelance Web Designer KeithMcL's Avatar
    Join Date
    Oct 1999
    Location
    Dublin, Ireland
    Posts
    1,125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured this exact problem out in my previous job on a project. I can't remember what code I used, but I remember that I had to get the Javascript to recognise that the return hit had been pressed, which is number 13 on the keycode list (if I remember correctly).

    These links might help somewhat:

    http://www.allasp.net/enterkey.aspx
    http://www.cs.tut.fi/~jkorpela/forms/enter.html

  11. #11
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I GOT IT...
    strange though had to remove the form tag.

  12. #12
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    woo hoo!

  13. #13
    SitePoint Enthusiast kgish's Avatar
    Join Date
    Dec 2001
    Location
    Gouda, The Netherlands
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, removing the form-tag is not the correct way, as this introduces an incompatibility. Some browsers will even choke on a submit button that is not found within a form.

    The correct way to handle this is to place an onsubmit event handler in the form tag:
    Code:
    <form ... onsubmit="return submitHandler()">
    Kiffin
    Your average future-famous kind of guy...

  14. #14
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, perhaps then you can help me, since as soon as I add the form back it wont work....

    relevent code is in red...

    Code:
    <%@LANGUAGE="JAVASCRIPT"%>
    <html>
    <head>
    <title>Hand Held Item Entry</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript">
    function enterkey(eEvent) {
      if (eEvent.keyCode == 13){
    	submitDB();
     }
     return true;
    }
    function submitDB(){
    var itemnum = document.all.itemnumHolder.value;
    var readSource = 0;
    var readType = 0; 
    window.location.href = "PocketPCDetails.asp?ScanCheck=1&itemnum=" + itemnum + "&readSource=" + readSource + "&readType=" + readType;  
    }
    function logOff(){
    window.location.href="pocketLogin.asp";
    }
    </script>
    </head>
    <body bottommargin="0" topmargin="0" rightmargin="0" leftmargin="0">
    <form method="get" name="formhandheld" onsubmit="return enterkey()">
    <table width="225" border="0" cellpadding="0" cellspacing="0">
      <tr>
    	<td bgcolor="#e3e3e3" valign="top">
     <table width="100%" height="320" border="0" cellspacing="0" cellpadding="0">
    		<tr>
    			<td bgcolor="#e3e3e3" height="*" valign="top">
       <table width="100%" border="0" cellspacing="0" cellpadding="0">
    				<tr>
    	 <td colspan="2" align="center" bgcolor="#00CC33">
    	 <font size='-1' face='verdana,arial'>Hand Held Item Maintenance</font>
    	 </td>
    	 </tr>
    	 <tr>
    	  <td>&nbsp;</td><td>&nbsp;</td>
    	 </tr>
       <tr>
    	  <td colspan="2" align="center"><font face='verdana,arial'>Scan Item or Key Enter Item</font></td>
    	 </tr>
    	 <tr>
       <td align="center" colspan="2"><input name="itemnumHolder" type="text" onkeypress="return enterkey(event)" size="30" maxlength="13" ></td>
    	 </tr>
    	
    			  <tr>
       <td align="center" colspan="2">&nbsp;
       </td>
    	 </tr>  
    			   
    				
    			  </table>
       </td>
    		</tr>
    		<tr>
    		  <td bgcolor="#999999" height="28"><div align="center">
    	<input name="Log_Off" type="button" value="	Log Off	" onClick="logOff()"><br />
    				<input type="button" name="Details" value="&nbsp;Details&nbsp;" onClick="submitDB()">
    				<input type="reset" name="Cancel" value="&nbsp;Cancel&nbsp;">
    	 <input type="button" name="Help" value="&nbsp;&nbsp;&nbsp;Help&nbsp;&nbsp;&nbsp;" onClick="window.location.href="pocketScanItem_Help.asp"">
    			</div></td>
    		</tr>
    	  </table></td>
      </tr>
    </table>
    </form>
    </body>
    </html>


Bookmarks

Posting Permissions

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