I'm new to JavaScript and have had some success in basic validation but i cannot work out how to do this.
What i have is form which can have between 1 and 10 drop down boxes depending on the users selection. the values in these boxes a retrieved from my database. What I am trying to do is maake sure the user has not selected the same values more than once before i put this data back into my database.
The code below is what I have come up with so far. When the JavaScript function is run it returns to the same page but the alert appears on the site, but not in a popup box as it previously has when i have used it on other pages. It does see that the values have been selected more than once, but i have done something wrong as I get an undifined index error for php variables which previously had data in them.
<script type="text/javascript">
<!--
var nov = "document.getElementById("
NOV
").value == ''";
var checknov = new Array();
checknov[] == 0;
function validate_reg() {
while (nov > 0) {
for (var veh = checknov) {
if (document.getElementById("FLT").value == '' == veh) {
window.alert("You Cannot Assign The Same Vehicle More Than Once");
}
else {
checknov[] = document.getElementById("FLT").value == '';
}
}
nov--;
}
}
-->
</script>
I have added the Varible nov to the id as this is how it is defined in the form.
<script type="text/javascript">
<!--
var nov = document.getElementById("NOV").value == '';
var checknov=new Array();
checknov[]==0;
function validate_reg()
{
while (nov>0)
{
for (var veh=checknov)
{
if (document.getElementById("FLT"nov).value == '' == veh)
{
window.alert("You Cannot Assign The Same Vehicle More Than Once");
}
else
{
checknov[] = document.getElementById("FLT"nov).value == '';
}
}
nov--;
}
}
-->
</script>