Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   A little help on some Javascript (http://www.chiefdelphi.com/forums/showthread.php?t=126494)

cmockjr 15-02-2014 09:15

A little help on some Javascript
 
Ok, I have been trying to make a php file cancel submitting the data the user enters when two pieces of information are the same using javascript. As far as I know, what I have tried should be working fine but the form keeps on submitting. Here is what I have:
javascript:
<script type="text/javascript">
function validateForm()
{
var Team1=document.getElementById("Team1").value;
var Team2=document.getElementById("Team2").value;
var Team3=document.getElementById("Team3").value;
if (Team1 != Team2) && (Team1 != Team3) && (Team2 != Team3)
{
return true;
} else {
alert('Choose 3 different Teams for the Match!');
return false;
}
}
</script>
HTML/PHP that is used to submit the match by activating another PHP file that submits the match to a database:
<input type="submit" value="Add/Update" style="margin: 0 auto" formaction="MatchTable.php" onsubmit="return validateForm();">
If anyone could help me on this, it would be really awesome.

RyanCahoon 15-02-2014 16:58

Re: A little help on some Javascript
 
See this StackOverflow thread

artdutra04 15-02-2014 18:45

Re: A little help on some Javascript
 
You need to wrap another set of parenthesis around the if statement to prevent a syntax error.

Code:

if (Team1 != Team2) && (Team1 != Team3) && (Team2 != Team3)
should be

Code:

if ((Team1 != Team2) && (Team1 != Team3) && (Team2 != Team3))


All times are GMT -5. The time now is 11:33.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi