Page 1 of 1
javascript validation for a checkbox
Posted: Wed Apr 04, 2007 9:42 pm
by izzysanime
Hi, how do i make a validation script for a checkbox, I have php require the text fields, but it wont work for a checkbox.
any ideas?
Josh
Re: javascript validation for a checkbox
Posted: Wed Apr 04, 2007 10:21 pm
by izzysanime
well, i got something, but it wont work. No matter what I select, yes or no, it always displays the same response.
any ideas
if($t27=="1"){
echo "alert('Thank You for Agreeing to Terms & Conditions');";
// ... checkbox1 has been checked, form processing code here
} else {
echo "alert('Error! You must agree to the terms and conditions!');history.back(-1);"; // ... checkbox1 has NOT been checked, form processing code here
}
This is the html part of the form
Yes
No
Re: javascript validation for a checkbox
Posted: Wed Apr 04, 2007 11:30 pm
by Nullig
What is the html code on the form?
Nullig
Re: javascript validation for a checkbox
Posted: Tue Apr 10, 2007 3:53 pm
by Kayin
if($_POST['input_checkbox_field'] == "on") {
...code here
}
checkboxes will post either "on" or "off" its' weird.
-K
Re: javascript validation for a checkbox
Posted: Thu Apr 19, 2007 6:11 pm
by izzysanime
ok, here is the form, I used a script from dynamicdrive.com and it works with a checkbox on their site. But not mine of course. here is the link
http://wareriver.com/clients/fs/form.html
any ideas would be great
thanks
Josh
Re: javascript validation for a checkbox
Posted: Thu Apr 19, 2007 6:17 pm
by izzysanime
if someone has some code on them for validating a checkbox, I will try that.
Re: javascript validation for a checkbox
Posted: Mon Apr 23, 2007 2:50 am
by JohnnyB
if($_POST['input_checkbox_field'] == "on") {
...code here
}
Did this work for you?
I think what is meant is
if($_POST['t27'] == "on") {
echo "alert('Thank You for Agreeing to Terms & Conditions');";
// ... checkbox1 has been checked, form processing code here
} else {
echo "alert('Error! You must agree to the terms and conditions!');history.back(-1);"; // ... checkbox1 has NOT been checked, form processing code here
}
Re: javascript validation for a checkbox
Posted: Mon May 07, 2007 9:22 pm
by Kayin
..that is what I put, just in fewer words. lol
-E
Re: javascript validation for a checkbox
Posted: Wed May 09, 2007 2:20 am
by izzysanime
Sorry, Ill try it in the morning. I just made a text field where the person has to type in yes rather than check it. Ill try it, I think that would be better than just a text box.
thanks
Josh