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 Link to comment https://forums.phpfreaks.com/topic/104819-help-with-and/ 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. Link to comment https://forums.phpfreaks.com/topic/104819-help-with-and/#findComment-536565 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 Link to comment https://forums.phpfreaks.com/topic/104819-help-with-and/#findComment-536588 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.