Enter Key Disabling/Form Validation


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Enter Key Disabling/Form Validation

  1. #1
    Mike Ewert Guest

    Enter Key Disabling/Form Validation


    Does anyone have a script which I can use to prevent the sending of
    form information when the user hits the enter key?. I have seen
    several scripts that purport to solve this problem, but none of them
    work. I have tried to code my own script, but so far no luck, mainly
    the enter key ascii equivalent, but so far no luck. Appreciate any help.


    Mike Ewert


  2. #2
    Matt Markus Guest

    Re: Enter Key Disabling/Form Validation

    Hi Mike --

    "Mike Ewert" <ewert@flashmail.com> wrote in message
    news:3b26a516@news.devx.com...
    >
    > Does anyone have a script which I can use to prevent the sending of
    > form information when the user hits the enter key?. I have seen
    > several scripts that purport to solve this problem, but none of them
    > work. I have tried to code my own script, but so far no luck, mainly
    > the enter key ascii equivalent, but so far no luck. Appreciate any help.
    >
    >
    > Mike Ewert
    >


    Just off the top of my head, don't make your button a submit button, but
    just a regular button. Then onClick(), call your submit routine.

    <form name=form1>
    <input type="button" value="Submit" name="cmdSubmit"
    onClick="SubmitForm();">
    </form>

    <script language="javascript">
    function SubmitForm()
    {
    document.form1.submit();
    }
    </script>

    By making the button type="button", pressing enter won't cause the button to
    submit the form.


    -Matt



  3. #3
    Russell Jones Guest

    Re: Enter Key Disabling/Form Validation

    Change the action attribute of the form so that it calls a script function.
    You can then submit the form to the appropriate location within the function
    after processing the form data, or you can prevent submission altogether.

    "Mike Ewert" <ewert@flashmail.com> wrote in message
    news:3b26a516@news.devx.com...
    >
    > Does anyone have a script which I can use to prevent the sending of
    > form information when the user hits the enter key?. I have seen
    > several scripts that purport to solve this problem, but none of them
    > work. I have tried to code my own script, but so far no luck, mainly
    > the enter key ascii equivalent, but so far no luck. Appreciate any help.
    >
    >
    > Mike Ewert
    >




  4. #4
    Matt Markus Guest

    Re: Enter Key Disabling/Form Validation

    Oops!

    "Matt Markus" <matt_markus@hotmail.com> wrote in message
    news:3b30be10@news.devx.com...
    > Hi Mike --
    >
    > "Mike Ewert" <ewert@flashmail.com> wrote in message
    > news:3b26a516@news.devx.com...
    > >
    > > Does anyone have a script which I can use to prevent the sending of
    > > form information when the user hits the enter key?. I have seen
    > > several scripts that purport to solve this problem, but none of them
    > > work. I have tried to code my own script, but so far no luck, mainly
    > > the enter key ascii equivalent, but so far no luck. Appreciate any help.
    > >
    > >
    > > Mike Ewert
    > >

    >
    > Just off the top of my head, don't make your button a submit button, but
    > just a regular button. Then onClick(), call your submit routine.
    >
    > <form name=form1>
    > <input type="button" value="Submit" name="cmdSubmit"
    > onClick="SubmitForm();">
    > </form>
    >
    > <script language="javascript">
    > function SubmitForm()
    > {
    > document.form1.submit();
    > }
    > </script>
    >
    > By making the button type="button", pressing enter won't cause the button

    to
    > submit the form.
    >
    >
    > -Matt
    >
    >


    Ok, I just found some problems with my previous example, so try this
    instead:

    <form name=form1 action=post.htm method=post>
    <input type=button name=cmdSubmit value="click" onfocus="RedirectFocus();"
    onClick="SubmitForm();">
    <input type=text name=text1 size=20>
    <input type=text name=text2 size=20>
    </form>

    <script language="javascript">
    function SubmitForm()
    {
    document.form1.submit();
    }

    function RedirectFocus()
    {
    document.form1.text2.focus();
    }
    </script>

    Cheesey, but it works.

    It seems that when the text box next to the button receives the focus, so
    does the button, and thus pressing enter will then cause that button to be
    clicked. So just set the focus to another control every time that button
    receives the focus.

    Hope this helps!




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center