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
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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.