Click to See Complete Forum and Search --> : Confirm box script when checkbox is unchecked


Pat Sanders
09-23-2003, 07:21 AM
I have a form where the last item is a checkbox that the user is not required to check, but before they submit the form I want to verify that they have not forgotten to check the checkbox. Every confirm box script I have seen has an if else statement that refreshes the page. I do not want the user to lose the information in the other form fields. I need for the script to simply either focus on the field(checkbox) (if yes) or stay on the current page (if no) so they can submit the form.

Here is the url to the page:http://www.cctech.edu/cgi-bin/forms/grad_placement.asp

the checkbox in question is the last field on the form.

I have a function in the form which does all the validation -
<form name="form1" action="/cgi-bin/forms/grad_thks.asp" method="post" onSubmit="return ValidateForm() ">

function ValidateForm() {

Charles
09-23-2003, 07:36 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
-->
</style>

<script type="text/javascript">
<!--
function validate (f) {if (!f.devil.checked && confirm('Would you like fame, fortune and great sex?')) {f.devil.focus(); return false}}
// -->
</script>

<form action="" onsubmit="return validate(this)">
<div>
<label><input type="checkbox" name="devil">Sell Soul to the Devil</label>
<button type="submit">Submit</button>
</div>
</form>

Pat Sanders
09-23-2003, 08:00 AM
Thanks Charles, I knew there was a simple solution.
That works! :D