html form validation

Discussion in 'HTML' started by Shailesh, Sep 13, 2004.

  1. Shailesh

    Shailesh Guest

    Hello,

    I am new to this group and I have a simple question about an html form. I
    have a check box field for user to select if they agree with my terms. Then
    click on submit button. I want a message box appear, if a user has not
    selected the check box field when click on submit button. Could someone help
    me with that code? Thank you in advance.

    Sam
    Shailesh, Sep 13, 2004
    #1
    1. Advertising

  2. Shailesh

    Mark Parnell Guest

    On Mon, 13 Sep 2004 04:22:44 GMT, Shailesh <>
    declared in alt.html:

    > Hello,


    G'day.

    > I am new to this group


    We all were once. :)

    > and I have a simple question about an html form. I
    > have a check box field for user to select if they agree with my terms. Then
    > click on submit button. I want a message box appear, if a user has not
    > selected the check box field when click on submit button. Could someone help
    > me with that code? Thank you in advance.


    If you want a message box to pop up as soon as they try to submit the
    form, you will need to use Javascript. I can't help you much there,
    though others no doubt can.

    If you want to show an error page (which you should do anyway in case
    client-side scripting is disabled/unavailable), you need to check
    whether the checkbox is selected in your form handler. How to do that
    depends on what language the form handler is written in.

    --
    Mark Parnell
    http://www.clarkecomputers.com.au
    "Never drink rum&coke whilst reading usenet" - rf 2004
    Mark Parnell, Sep 13, 2004
    #2
    1. Advertising

  3. Shailesh wrote:
    > I am new to this group and I have a simple question about an html form. I
    > have a check box field for user to select if they agree with my terms. Then
    > click on submit button. I want a message box appear, if a user has not
    > selected the check box field when click on submit button. Could someone help
    > me with that code? Thank you in advance.


    This should work, but make sure to also check it server-side:

    <script type="text/javascript">
    function validate_checkbox() {
    var checkbox = document.getElementById('checkbox');
    if (!checkbox.checked) {
    alert("The check box must be checked.");
    return false;
    } else {
    return true;
    }
    }
    </script>
    <form action="foo.html" onsubmit="return validate_checkbox()">
    <p><label for="checkbox">Check this:</label>
    <input type="checkbox" id="checkbox"></p>
    <p><input type="submit" value="Submit"></p>
    </form>
    Leif K-Brooks, Sep 13, 2004
    #3
  4. "Shailesh" <> wrote:

    > I have a check box field for user to select if they agree with my
    > terms. Then click on submit button. I want a message box appear, if a
    > user has not selected the check box field when click on submit
    > button.


    Don't bother. It won't have the legal impact that clueless authors
    assume. If your lawyer has said otherwise, ask him to cite a court
    decision that is relevant. (Spoiler: ur jba'g, orpnhfr ur pna'g, ohg lbh
    znl rawbl gur ireony qvneeurn cerfragrq vafgrnq.)

    It's just an annoyance, and people either go elsewhere after the
    disruption, or check the box without reading your terms, and without
    committing themselves to them.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
    Jukka K. Korpela, Sep 13, 2004
    #4
  5. Shailesh

    Sam Hughes Guest

    SPOILER (was Re: html form validation)

    "Jukka K. Korpela" <> wrote in
    news:Xns95635C2AC1D84jkorpelacstutfi@193.229.0.31:

    > (Spoiler: ur jba'g, orpnhfr ur pna'g, ohg lbh
    > znl rawbl gur ireony qvneeurn cerfragrq vafgrnq.)


    Nice cipher puzzle ;-) Answer re-encrypted with ROT-26 for the ROT-13-
    clueless...
    he won't, because he can't, but you
    may enjoy the verbal diarrhea presented instead.
    Sam Hughes, Sep 14, 2004
    #5
  6. Shailesh

    Neal Guest

    Re: SPOILER (was Re: html form validation)

    On 14 Sep 2004 06:26:03 GMT, Sam Hughes <> wrote:

    > "Jukka K. Korpela" <> wrote in
    > news:Xns95635C2AC1D84jkorpelacstutfi@193.229.0.31:
    >
    >> (Spoiler: ur jba'g, orpnhfr ur pna'g, ohg lbh
    >> znl rawbl gur ireony qvneeurn cerfragrq vafgrnq.)

    >
    > Nice cipher puzzle ;-) Answer re-encrypted with ROT-26 for the ROT-13-
    > clueless...
    > (snip)


    Thanks, that ROT-26 is so much easier to decipher... ;)
    Neal, Sep 14, 2004
    #6
  7. Shailesh

    Shailesh Guest

    Thanks for the reply. The form handler is written in HTML? (not sure) using
    MS FrontPage.



    "Mark Parnell" <> wrote in message
    news:1hy87d9mw4lsl$...
    > On Mon, 13 Sep 2004 04:22:44 GMT, Shailesh <>
    > declared in alt.html:
    >
    > > Hello,

    >
    > G'day.
    >
    > > I am new to this group

    >
    > We all were once. :)
    >
    > > and I have a simple question about an html form. I
    > > have a check box field for user to select if they agree with my terms.

    Then
    > > click on submit button. I want a message box appear, if a user has not
    > > selected the check box field when click on submit button. Could someone

    help
    > > me with that code? Thank you in advance.

    >
    > If you want a message box to pop up as soon as they try to submit the
    > form, you will need to use Javascript. I can't help you much there,
    > though others no doubt can.
    >
    > If you want to show an error page (which you should do anyway in case
    > client-side scripting is disabled/unavailable), you need to check
    > whether the checkbox is selected in your form handler. How to do that
    > depends on what language the form handler is written in.
    >
    > --
    > Mark Parnell
    > http://www.clarkecomputers.com.au
    > "Never drink rum&coke whilst reading usenet" - rf 2004
    Shailesh, Sep 14, 2004
    #7
  8. Shailesh

    Shailesh Guest

    Thanks for your help. I will certainly try the javascript you have provided.


    "Leif K-Brooks" <> wrote in message
    news:...
    > Shailesh wrote:
    > > I am new to this group and I have a simple question about an html form.

    I
    > > have a check box field for user to select if they agree with my terms.

    Then
    > > click on submit button. I want a message box appear, if a user has not
    > > selected the check box field when click on submit button. Could someone

    help
    > > me with that code? Thank you in advance.

    >
    > This should work, but make sure to also check it server-side:
    >
    > <script type="text/javascript">
    > function validate_checkbox() {
    > var checkbox = document.getElementById('checkbox');
    > if (!checkbox.checked) {
    > alert("The check box must be checked.");
    > return false;
    > } else {
    > return true;
    > }
    > }
    > </script>
    > <form action="foo.html" onsubmit="return validate_checkbox()">
    > <p><label for="checkbox">Check this:</label>
    > <input type="checkbox" id="checkbox"></p>
    > <p><input type="submit" value="Submit"></p>
    > </form>
    Shailesh, Sep 14, 2004
    #8
  9. Shailesh

    Mark Parnell Guest

    On Tue, 14 Sep 2004 17:13:25 GMT, Shailesh <>
    declared in alt.html:

    > Thanks for the reply. The form handler is written in HTML? (not sure) using
    > MS FrontPage.


    No, HTML cannot actually _do_ anything. It simply describes the
    structure of the content of your page. The form handler is whatever is
    in the action="" attribute of your <form>. If you didn't write it, then
    you will need to consult the documentation, or contact the person who
    did write it.

    BTW: Please don't post upside down.
    http://www.allmyfaqs.com/faq.pl?How_to_post
    http://en.wikipedia.org/wiki/Top-posting

    This will help:
    http://home.in.tum.de/~jain/software/oe-quotefix/

    --
    Mark Parnell
    http://www.clarkecomputers.com.au
    "Never drink rum&coke whilst reading usenet" - rf 2004
    Mark Parnell, Sep 15, 2004
    #9
  10. Shailesh

    selvamgt

    Joined:
    Oct 25, 2007
    Messages:
    1
    Hi,

    I have a question in HTML form.
    I have multiple checkbox field. I want a message to be appear for each and every checkbox field if the user has not selected the checkbox field when click on submit button.
    Can you pls tell me how to validate multiple checkbox in HTML form.

    Regards,
    Selvam
    selvamgt, Oct 25, 2007
    #10
    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. Colin Basterfield

    Web form validation vs object validation

    Colin Basterfield, Nov 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    421
    Tommy
    Nov 29, 2003
  2. Sumith Mathur
    Replies:
    0
    Views:
    2,188
    Sumith Mathur
    Sep 23, 2004
  3. OriginalBrownster

    string validation/ form validation

    OriginalBrownster, Aug 21, 2006, in forum: Python
    Replies:
    1
    Views:
    411
    Simon Forman
    Aug 21, 2006
  4. Grigory Temchenko
    Replies:
    0
    Views:
    316
    Grigory Temchenko
    Dec 28, 2008
  5. bnp
    Replies:
    4
    Views:
    293
Loading...

Share This Page