javascript validation for a checkbox

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
izzysanime

javascript validation for a checkbox

Post 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
izzysanime

Re: javascript validation for a checkbox

Post 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
                                             
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: javascript validation for a checkbox

Post by Nullig »

What is the html code on the form?

Nullig
Kayin
Forum Members
Forum Members
Posts: 59
Joined: Mon Jun 05, 2006 2:33 am

Re: javascript validation for a checkbox

Post by Kayin »

if($_POST['input_checkbox_field'] == "on") {

...code here

}


checkboxes will post either "on" or "off"  its' weird.

-K
izzysanime

Re: javascript validation for a checkbox

Post 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
izzysanime

Re: javascript validation for a checkbox

Post by izzysanime »

if someone has some code on them for validating a checkbox, I will try that.
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: javascript validation for a checkbox

Post 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

}
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
Kayin
Forum Members
Forum Members
Posts: 59
Joined: Mon Jun 05, 2006 2:33 am

Re: javascript validation for a checkbox

Post by Kayin »

..that is what I put, just in fewer words. lol

-E
Last edited by Kayin on Mon May 07, 2007 9:41 pm, edited 1 time in total.
izzysanime

Re: javascript validation for a checkbox

Post 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
Post Reply

Return to “The Lounge”