html form validation

S

Shailesh

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
 
M

Mark Parnell

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.
 
L

Leif K-Brooks

Shailesh said:
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>
 
J

Jukka K. Korpela

Shailesh said:
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.
 
S

Sam Hughes

(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.
 
S

Shailesh

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

Mark Parnell

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/
 
Joined
Oct 25, 2007
Messages
1
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top