Jump to content

Simple Validation Not Working


sweinkauf13

Recommended Posts

Hello,I have a page that has 2 "team selections" on it. just 2 radio sets. Now when it is submitted it is supose to validate() and see if team1 is equal to team2. if it is, it is supose to stop the submission and alert(). And if team1 is not eqaul to team2 then it should carry on as directed. But right now it does not seem to validate(). Even when i set both team1 and team2 to the same value it does not stop the submission and it submits to the start.php script. I'm not sure why it is not stopping me. Please help me!here is the code:

<html><head><title>Hockey</title><style>img.teamlogo{height: 100pt;width: 100pt;}</style><script LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">function validate(){team1 = document.form.team1.value;team2 = document.form.team2.value;if(team1 == team2){alert("Sorry, you have set both teams to the same thing\n Please select two DIFFERENT teams");}}</script></head><body><p>Player 1 please pick your team:</p><form method="post" action="start.php" onsubmit="validate()"><p><table cellspacing="10" cellpadding="5" rules=cols><tr><td><img src="admirals.png" class="teamlogo"></td><td><img src="energy.jpg" class="teamlogo"></td><td><img src="avalanche.gif" class="teamlogo"></td><td><img src="mapleleafs.gif"class="teamlogo"></td><td><img src="predators.gif" class="teamlogo"></td></tr><tr align="center"><td><input type="radio" name="team1" value="admirals.png"></td><td><input type="radio" name="team1" value="energy.jpg"></td><td><input type="radio" name="team1" value="avalanche.gif"></td><td><input type="radio" name="team1" value="mapleleafs.gif"></td><td><input type="radio" name="team1" value="predators.gif"></td></tr></table></p><p>Player 2 please pick your team:</p><p><table cellspacing="10" cellpadding="5" rules=cols><tr><td><img src="admirals.png" class="teamlogo"></td><td><img src="energy.jpg" class="teamlogo"></td><td><img src="avalanche.gif" class="teamlogo"></td><td><img src="mapleleafs.gif"class="teamlogo"></td><td><img src="predators.gif" class="teamlogo"></td></tr><tr align="center"><td><input type="radio" name="team2" value="admirals.png"></td><td><input type="radio" name="team2" value="energy.jpg"></td><td><input type="radio" name="team2" value="avalanche.gif"></td><td><input type="radio" name="team2" value="mapleleafs.gif"></td><td><input type="radio" name="team2" value="predators.gif"></td></tr></table></p><p align="right"><input type="submit" value="START"></p></form></body></html>

Thanks in advance,youngwebmaster

Link to comment
Share on other sites

Remove language=javascript. It is not the standard, nor does it do anything. Also add a doctype first. In my opinion, JavaScript and valid html go hand in hand.

Link to comment
Share on other sites

Ok. I added doctype and took out language=javascript. But i still get the same result. Anything else i can do?

Link to comment
Share on other sites

Of course the form submits. You haven't told it not to. The submit object needs to receive a value of false to stop submission. If you want to define your handler in the tag (that's what you are doing) you need these changes:1. Your handler (the validate() function) should return a Boolean value. True means continue submitting. False means you have intercepted the event, and submission should be stopped.2. The definition in your tag should look like this: onsubmit="return validate()"FWIW, the suggestions you received in Post #2 are useful, but unrelated to this issue.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...