Validate that a button was clicked

Discussion in 'HTML' started by news.telkomsa.net, Jul 26, 2004.

  1. Hi,

    I have been trying to ensure that a button is clicked to submit a form. I
    have a form with a various fields and a button with a validation script but
    the user can press enter on any one of the text input fields, and the form
    submits to the "action" page without running the validation.

    Could someone give me a pointer?

    Thanks
    Antony
    news.telkomsa.net, Jul 26, 2004
    #1
    1. Advertising

  2. news.telkomsa.net

    JayB Guest

    "news.telkomsa.net" <> wrote in message
    news:ce3ql5$ovq$...
    > Hi,
    >
    > I have been trying to ensure that a button is clicked to submit a form. I
    > have a form with a various fields and a button with a validation script

    but
    > the user can press enter on any one of the text input fields, and the form
    > submits to the "action" page without running the validation.
    >
    > Could someone give me a pointer?


    Does the button need to be clicked for a reason other than validation?

    I don't know what language you're using but here's some simple ASP that will
    work whether the button is clicked or the enter key is depressed.

    <body>

    <%
    if request.form("submit") = "go" then
    'ENTER VALIDATION CODE HERE
    end if
    %>

    <form action="text.asp" method="post">
    <input type="text" name="name"><br>
    <input type="submit" name="submit" value="go">
    </form>

    </body>

    --
    JayB
    JayB, Jul 26, 2004
    #2
    1. Advertising

  3. No the button need only be clicked for validation. I am using asp and
    vbscript for the validation, but I want to pop-up message boxes with errors
    prior to submitting the form.

    I suppose that I am looking for a way to ignore the enter key or stop the
    enter key from submitting the form.

    Regards,
    Antony


    "JayB" <> wrote in message
    news:AdeNc.1031$...
    >
    > "news.telkomsa.net" <> wrote in message
    > news:ce3ql5$ovq$...
    > > Hi,
    > >
    > > I have been trying to ensure that a button is clicked to submit a form.

    I
    > > have a form with a various fields and a button with a validation script

    > but
    > > the user can press enter on any one of the text input fields, and the

    form
    > > submits to the "action" page without running the validation.
    > >
    > > Could someone give me a pointer?

    >
    > Does the button need to be clicked for a reason other than validation?
    >
    > I don't know what language you're using but here's some simple ASP that

    will
    > work whether the button is clicked or the enter key is depressed.
    >
    > <body>
    >
    > <%
    > if request.form("submit") = "go" then
    > 'ENTER VALIDATION CODE HERE
    > end if
    > %>
    >
    > <form action="text.asp" method="post">
    > <input type="text" name="name"><br>
    > <input type="submit" name="submit" value="go">
    > </form>
    >
    > </body>
    >
    > --
    > JayB
    >
    >
    Antony Futter, Jul 26, 2004
    #3
  4. news.telkomsa.net

    SpaceGirl Guest

    Antony Futter wrote:

    > No the button need only be clicked for validation. I am using asp and
    > vbscript for the validation, but I want to pop-up message boxes with errors
    > prior to submitting the form.
    >
    > I suppose that I am looking for a way to ignore the enter key or stop the
    > enter key from submitting the form.
    >
    > Regards,
    > Antony
    >
    >
    > "JayB" <> wrote in message
    > news:AdeNc.1031$...
    >
    >>"news.telkomsa.net" <> wrote in message
    >>news:ce3ql5$ovq$...
    >>
    >>>Hi,
    >>>
    >>>I have been trying to ensure that a button is clicked to submit a form.

    >
    > I
    >
    >>>have a form with a various fields and a button with a validation script

    >>
    >>but
    >>
    >>>the user can press enter on any one of the text input fields, and the

    >
    > form
    >
    >>>submits to the "action" page without running the validation.
    >>>
    >>>Could someone give me a pointer?

    >>
    >>Does the button need to be clicked for a reason other than validation?
    >>
    >>I don't know what language you're using but here's some simple ASP that

    >
    > will
    >
    >>work whether the button is clicked or the enter key is depressed.
    >>
    >><body>
    >>
    >><%
    >>if request.form("submit") = "go" then
    >>'ENTER VALIDATION CODE HERE
    >>end if
    >>%>
    >>
    >><form action="text.asp" method="post">
    >><input type="text" name="name"><br>
    >><input type="submit" name="submit" value="go">
    >></form>
    >>
    >></body>
    >>
    >>--
    >>JayB
    >>
    >>

    >
    >
    >


    <script type="text/javascript">

    validateMe () {

    if (form1.something.value) == "" {

    alert("you must complete all items");

    }

    if (form.something.value) != ""

    form1.submit;

    }

    }

    </script>

    ....


    <form action="text.asp" onsubmit="validateMe();">

    <form item />

    </form>

    ....

    --


    x theSpaceGirl (miranda)

    # lead designer @ http://www.dhnewmedia.com #
    # remove NO SPAM to email, or use form on website #
    SpaceGirl, Jul 26, 2004
    #4
  5. news.telkomsa.net

    Toby Inkster Guest

    news.telkomsa.net wrote:

    > I have a form with a various fields and a button with a validation
    > script but the user can press enter on any one of the text input fields,
    > and the form submits to the "action" page without running the validation.


    How are you running the validation script?

    <input type="submit" onclick="blah">?

    If so, change it to:

    <input type="submit">

    and then change your <form> element to:

    <form onsubmit="blah">

    Ought to work.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Jul 26, 2004
    #5
  6. Hi,

    I have tried all the various things that people have suggested, but I must
    be doind something really silly. I have posted the page to
    www.asf.co.za/test/input.asp which then pops up the errors, but continues to
    post to the next page, irrelavent of whether or not the button was
    clicked/pressed.

    Please could someone help?

    Thanks
    Antony

    "news.telkomsa.net" <> wrote in message
    news:ce3ql5$ovq$...
    > Hi,
    >
    > I have been trying to ensure that a button is clicked to submit a form. I
    > have a form with a various fields and a button with a validation script

    but
    > the user can press enter on any one of the text input fields, and the form
    > submits to the "action" page without running the validation.
    >
    > Could someone give me a pointer?
    >
    > Thanks
    > Antony
    >
    >
    Antony Futter, Jul 27, 2004
    #6
  7. news.telkomsa.net

    Toby Inkster Guest

    Toby Inkster, Jul 27, 2004
    #7
    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. Mossman
    Replies:
    0
    Views:
    766
    Mossman
    Dec 12, 2005
  2. albert kao
    Replies:
    1
    Views:
    1,995
    marisa lee
    Apr 10, 2010
  3. bthumber
    Replies:
    4
    Views:
    451
    bthumber
    Jun 25, 2010
  4. Dave Prout

    Adding a second button if the first button is clicked

    Dave Prout, Jun 8, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    196
    John Saunders
    Jun 8, 2004
  5. Jim Mitchell
    Replies:
    0
    Views:
    179
    Jim Mitchell
    Jul 12, 2003
Loading...

Share This Page