Forum Moderators: open

Message Too Old, No Replies

Form If Then Syntax Question

form script if then checkboxes

         

Becca800

5:20 pm on Aug 10, 2007 (gmt 0)

10+ Year Member



Hi there. I have a form which requires two checkboxes to be checked before it can be sent. The action is for it to be emailed to me. I have it so if one of these checkboxes are not checked, an alert shows. However, when you press ok on the alert box, it still goes through with the action and the email is sent.

Here is the script:

<script type="text/javascript">
function Check() {
if(document.story.eighteen.checked == false)
{ alert('Please check the box if you are 18 or over.'); }
if(document.story.permission.checked == false)
{ alert('Please check the box to give us permission to reprint.'); }
}

</script>

Here is the form:

<form name="story" method="POST" action="/ad/submitfantasy/contact.asp">
<table width="35%"><tr><td width="25%">
<p><font face="arial black" color="#c11b17"><b><i>I am a man:</i></b></font><br>
<input type="checkbox" name="Iamaman" value="Yes">
</td><td width="25%"><font face="arial black" color="#c11b17"><b><i>I am a woman:</i></b></font><br>
<input type="checkbox" name="Iamawoman" value="Yes"></td></tr>
</table>
<font face="arial black" color="#c11b17"><b><i>I am 18 or over:</i></b></font><br>
<input type="checkbox" name="eighteen" value="Yes">
<p><font face="arial black" color="#c11b17"><b><i>May we have permission to publish this fantasy?</i></b></font><br>
<input type="checkbox" name="permission" value="Yes">
<p><font face="arial black" color="#c11b17"><b><i>My Fantasy:</i></b></font><br>
<textarea name="MyFantasy" rows="25" cols="100"></textarea>
<p><input type="submit" name="submit" value="Submit" onclick="Check()">
</form>

I tried putting this at the end of the script, but it didn't work. Instead it would just refresh the page, no alert boxes, no action.

if(document.story.eighteen.checked == true) && (document.story.permission.checked == true) {
document.story.action = '/ad/submitfantasy/contact.asp'; }

Fotiman

6:26 pm on Aug 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




<script type="text/javascript">
function Check() {
if(document.story.eighteen.checked == false) {
alert('Please check the box if you are 18 or over.');
[b]return false;[/b]
}
if(document.story.permission.checked == false) {
alert('Please check the box to give us permission to reprint.');
[b]return false;[/b]
}
}
</script>


<form name="story" method="POST" action="/ad/submitfantasy/contact.asp" [b]onsubmit="return Check();"[/b]>
...
<input type="submit" name="submit" value="Submit">
</form>

[edited by: Fotiman at 6:32 pm (utc) on Aug. 10, 2007]

Becca800

10:47 pm on Aug 10, 2007 (gmt 0)

10+ Year Member



THANK YOU!
That works perfectly.