Jump to content

Help with == and !=.


jkkenzie

Recommended Posts

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

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

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.