Forum Moderators: open
If anyone can help me out, or at least point me to a resource which might help, I would be grateful. Thanks.
function didYouCheckIt()
{
if (!document.getElementById('myCheckBox').checked) {
alert('You must check the box.')
return false
}
return true
}
}
click a checkbox and click a button to continue to the destination.
Also, no reason to return true. Return false stops the form from performing it's normal function onSubmit, so you want to let the Javascript manage the submit:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<!-- doctype all on one line -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Checkbox</title>
<script type="text/javascript">
function didYouCheckIt() {
if (! document.getElementById('myCheckBox').checked) {
alert('You must check the box.')
}
else { form.submit(); }
return false;
}
</script>
</head>
<body>
<form method="get" action="http://www.example.com" onSubmit="return didYouCheckIt();">
<input type="checkbox" name="myCheckBox" id="myCheckBox"> I have read the TOS
<input type="submit" value="Go">
</form>
</body>
</html>
<form method="get" action="http://www.example.com" onSubmit="return didYouCheckIt();">
how can I pass the url passthrough.html on the referring page, for example,
<a href="validate.html?passthrough.html">go here</a>
to the action attribute in the form?
A discussion of this approach is here [webmasterworld.com] including a complete sample script to do the job.
Basically all you'd do is put this Javascript on the "exit page." Come to think of it, if you redirect them to the "exit page", in effect you probably wouldn't need the check box.
Why not go for a more modern server side language, like PHP or ASP.NET?
Well, no good reason, I guess except, as a cut and paster, I've had some experience working with Perl scripts, plus the script Rocknbil referred me to is a Perl script. I just don't know enough to write code from scratch (I was a communications major 30 years ago - no programming ability at all! ;)