Page 1 of 1

making sure a checkbox is clicked

Posted: Thu Oct 27, 2005 1:02 pm
by Luke
I am making a form that posts variables to paypal, and I want to make sure that the customer clicks an "I agree to these terms" button before they submit. Is there an easy javascript or something that will make sure that check box is clicked, and if not, make a little box pop up and bitch at them?

Posted: Thu Oct 27, 2005 1:19 pm
by Luke
OK, i figured out a way to do get the box to pup up, but it still lets the form be posted and now after the box pops up, all the information in the box disappears. How do I get it to stay there?

Posted: Thu Oct 27, 2005 2:51 pm
by JayBird

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script>
function acceptTerms() {
	
	if (document.forms['theForm'].elements['theCheckbox'].checked == false) {
		
		alert('Please check the box to continue.');
		return false;

		
	} else {
		return true;

	}
}
</script>
</head>

<body>



<form action="" method="get" name="theForm" onsubmit="return acceptTerms()"/>

<input name="theCheckbox" type="checkbox" value="1" />

<input name="" type="submit" />

</form>
</body>
</html>

Posted: Fri Oct 28, 2005 10:11 am
by pickle
You could pop up a confirm() box rather than an alert() box. Confirm will return false if the user clicks 'Cancel', and true if the user clicks 'OK'.

Code: Select all

<script>
<html>
<head>
function doubleCheck()
{
   var myConfirm = confirm('Are you sure you want to confirm this?');
   return(myConfirm);
}
</script>
</head>
<body>
<form method = 'post' action = '$PHP_SELF' onSubmit = "return(doubleCheck());">
...
<input type = "submit">
</form>
</body>
</html>