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.
simple form submit
Moderator: General Moderators
-
andylyon87
- Forum Contributor
- Posts: 168
- Joined: Sat Jan 31, 2004 5:31 am
- Location: Dundee
Re: simple form submit
You can check the value of the checkbox using:
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(document.name_of_your_form.name_of_your_checkbox.checked == true){
document.getElementByID('my_div').innerHTML = 'Oops, you didnt check the checkbox';
}Code: Select all
if(!empty($_POST['name_of_your_checkbox'])){
$error .= 'Checkbox not checked'; // Remember to check $error later
}