jkkenzie Posted May 9, 2008 Share Posted May 9, 2008 this code does not work:(check at "!=" part) // Add-in validation for(var i=0; i<all_my_project_name.length; i++){ if(all_my_project_name[i] != form.name.value){ alert("This Project Does not Exist!"); form.name.focus(); return false; but this one works:(check at "==" part) // Add-in validation for(var i=0; i<all_my_project_name.length; i++){ if(all_my_project_name[i] == form.name.value){ alert("This Project Does not Exist!"); form.name.focus(); return false; Full code here: <?php echo '<script type="text/javascript"> <!-- var all_my_project_name = ['; $qry=mysql_query("SELECT name FROM tblcalc"); $counter=0; while($row = mysql_fetch_assoc($qry)) { $project[]=$row['name']; $counter++; } $write=0; while($write <= $counter) { if ($write < $counter) echo '"'.$project[$write].'"'.","; elseif($write == $counter) echo '"'.$project[$write].'"'; $write++; } $x="!="; echo ']; function validate ( form ) { if(form.name.value == "") { alert("Please fill in the field"); form.name.focus(); return false; } // Add-in validation for(var i=0; i<all_my_project_name.length; i++){ if(all_my_project_name[i] != form.name.value){ alert("This Project Does not Exist!"); form.name.focus(); return false; } } return true; } //--> </script>'; ?> Javscript Results are here: <script type="text/javascript"> <!-- var all_my_project_name = ["project1","project1","project1","project1","project1",""]; function validate ( form ) { if(form.name.value == "") { alert("Please fill in the field"); form.name.focus(); return false; } // Add-in validation for(var i=0; i<all_my_project_name.length; i++){ if(all_my_project_name[i] != form.name.value){ alert("This Project Does not Exist!"); form.name.focus(); return false; } } return true; } //--> </script> Thanks in advance Quote Link to comment Share on other sites More sharing options...
xenophobia Posted May 9, 2008 Share Posted May 9, 2008 Haha... I think there is no one else can help you in this problem except me... You did open a new thread actually huh? Is my bad... Actually your code should be like this: // Add-in validation for(var i=0; i<all_my_project_name.length; i++){ if(all_my_project_name[i] == form.name.value){ alert("This Project Exist!"); form.name.focus(); return false; } } You want to prompt if the same project existed right? I just catching the wrong idea... Sorry. Quote Link to comment Share on other sites More sharing options...
jkkenzie Posted May 9, 2008 Author Share Posted May 9, 2008 I guess its you and me only....... Your last code works but when i replace the ==(equal to) with the != (not equal to) it does not work. I would also to check on another page if the project does NOT exist.... Thanks again.. Regards, Joseph Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.