submit the form by clicking the button only.

Discussion in 'HTML' started by jrefactors@hotmail.com, Dec 23, 2004.

  1. Guest

    When the user type something in text box, and press enter, it will
    submit the form data
    to test2.jsp, even without pressing submit form button. This is not
    what I want, I want to
    submit the form only when the user press the submit button. Any
    workarounds? Please advise.
    thanks!!


    <script type="text/javascript">
    function submit_me()
    { alert("submit me");
    InputForm.submit();
    }
    </script>

    <FORM NAME="InputForm" ACTION="test2.jsp" METHOD="POST">
    name <input type="text" name="userName">
    <input type="button" onClick="submit_me()" value="submit form">
    </FORM>



    <%= request.getParameter("userName") %>
    , Dec 23, 2004
    #1
    1. Advertising

  2. Grant Wagner Guest

    <> wrote in message
    news:...
    > When the user type something in text box, and press enter, it will
    > submit the form data
    > to test2.jsp, even without pressing submit form button. This is not
    > what I want, I want to
    > submit the form only when the user press the submit button. Any
    > workarounds? Please advise.
    > thanks!!
    >
    >
    > <script type="text/javascript">
    > function submit_me()
    > { alert("submit me");
    > InputForm.submit();
    > }
    > </script>
    >
    > <FORM NAME="InputForm" ACTION="test2.jsp" METHOD="POST">
    > name <input type="text" name="userName">
    > <input type="button" onClick="submit_me()" value="submit form">
    > </FORM>


    You do not need JavaScript to submit the form. You might need JavaScript
    to do what you are attempting to do (suppress the ability for the submit
    to be invoked by the 'Enter' key), but you do not need it to submit the
    form.

    <!-- NO JAVASCRIPT NEEDED -->
    <form name="InputForm" action="test2.jsp" method="POST">
    name <input type="text" name="userName">
    <input type="submit" value="submit form">
    </form>

    As for messing with browser functionality and preventing the 'Enter' key
    from submitting the form, you can find multiple variations of that theme
    at:

    <url:
    http://www.google.ca/search?q=javascript prevent enter key submit form
    />

    --
    Grant Wagner <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Grant Wagner, Dec 23, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    6,167
  2. Network-Man
    Replies:
    5
    Views:
    78,211
    gaul1
    Jul 7, 2012
  3. Guest
    Replies:
    2
    Views:
    1,562
    Guest
    Oct 25, 2004
  4. Replies:
    1
    Views:
    140
    Grant Wagner
    Dec 23, 2004
  5. ljlolel
    Replies:
    2
    Views:
    492
Loading...

Share This Page