Page 1 of 1

simple form submit

Posted: Mon Jun 08, 2009 8:33 am
by andylyon87
Hey guys

Wondered if someone could point me in the direction of somewhere I can get the solution or idea behind how to do the following:

I have a form for a shopping cart, I need to only allow the submission of the form if the agree to terms and conditions box is ticked. If it isn't ticked I want to put an error on the page probs using innerHTML.

I am not very good at Javascript so any help would be great. Ive had a look on google but cannot find what Im after.

Re: simple form submit

Posted: Mon Jun 08, 2009 10:57 am
by mikemike
You can check the value of the checkbox using:

Code: Select all

 
if(document.name_of_your_form.name_of_your_checkbox.checked == true){
  document.getElementByID('my_div').innerHTML = 'Oops, you didnt check the checkbox';
}
But remember, you need to check server-side too, using something like PHP, otherwise I can turn JavaScript off and your script will be ignored.

Code: Select all

if(!empty($_POST['name_of_your_checkbox'])){
  $error .= 'Checkbox not checked'; // Remember to check $error later
}