4 Replies Latest reply on May 19, 2006 12:38 PM by Xtort

    Hitting Enter Key with online form

    Xtort Level 1
      When my users hit the enter key instead of clicking on submit, it just reloads the form and doubles any url variables that I'm passing. The page reloads itself

      <cfif isDefined('form.submit')>
      Perform actions
      <cfelse>
      Display form
      </cfif>

      The url would be http://192.168.1.1/test.cfm?cfid=3455 When the use hits enter it becomes http://192.168.1.1/test.cfm?cfid=3455cfid=3455. and just keeps adding everytime the user hits enter instead of clicking submit. Is there a way to make the enter key select the submit button by default?

      Thanks!
        • 1. Re: Hitting Enter Key with online form
          drforbin1970 Level 1
          You need to catch the Enter key press and kill it or convert it. You can kill the Enter keypress or convert it with the following:

          <head>
          <script>
          function kill_enter(kc){
          if(kc==13){
          //return event.keyCode=9; //moves cursor to next input
          return false; //kills the keypress
          }
          }
          </script>
          </head>

          <form name="myform2">
          <input type="text" name="y" onKeyDown="return kill_enter(event.keyCode);">
          <input type="text" name="z" onKeyDown="return kill_enter(event.keyCode);">
          <input type="submit">
          </form>

          Put the onKeyDown line on each input box but not the submit button.


          • 2. Re: Hitting Enter Key with online form
            Dan Bracuk Level 5
            Strictly a guess because you are not showing your form code, but, are you using method = "get" in your form? That might be messing it up. With a normal html form, the enter key will almost always submit the form.
            • 3. Re: Hitting Enter Key with online form
              Level 7
              Do you have an action assigned to the form tag? The only time I have run
              into this situation the client didn't have an action assigned in the form
              tag.

              --
              Bryan Ashcraft (remove brain to reply)
              Web Application Developer
              Wright Medical Technologies, Inc.
              =============================
              Macromedia Certified Dreamweaver Developer
              Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/


              "Xtort" <webforumsuser@macromedia.com> wrote in message
              news:e4ihm0$g93$1@forums.macromedia.com...
              > When my users hit the enter key instead of clicking on submit, it just
              > reloads
              > the form and doubles any url variables that I'm passing. The page reloads
              > itself
              >
              > <cfif isDefined('form.submit')>
              > Perform actions
              > <cfelse>
              > Display form
              > </cfif>
              >
              > The url would be <a target=_blank class=ftalternatingbarlinklarge
              > href=" http://192.168.1.1/test.cfm?cfid=3455">http://192.168.1.1/test.cfm?cfid=34
              > 55</a> When the use hits enter it becomes <a target=_blank
              > class=ftalternatingbarlinklarge
              > href=" http://192.168.1.1/test.cfm?cfid=3455cfid=3455.">http://192.168.1.1/test.c
              > fm?cfid=3455cfid=3455.</a> and just keeps adding everytime the user hits
              > enter
              > instead of clicking submit. Is there a way to make the enter key select
              > the
              > submit button by default?
              >
              > Thanks!
              >


              • 4. Re: Hitting Enter Key with online form
                Xtort Level 1
                Thanks the scritp you supplied worked like a charm!!

                Sincerely,
                Pauly