Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array

Status
Not open for further replies.

novice2004

Programmer
Feb 2, 2004
62
US
How should this should be done with an array help?
Thank you.



if(form.elements["state"].value != '3' || form.elements["state"].value != '6' || form.elements["state"].value != '23' ||
form.elements["state"].value != '33' || form.elements["state"].value != '34' || form.elements["state"].value != '41' ||
form.elements["state"].value != '42' || form.elements["state"].value != '43' || form.elements["state"].value != '46' ||
form.elements["state"].value != '49' || form.elements["state"].value != '50' || form.elements["state"].value != '52' ||
form.elements["state"].value != '64')
{
... something here
}
 
How should what be done with an Array?

What is it that you are trying to achieve?

If you want to check that a given string matches any element of an array of strings, you could do something like:
Code:
var arrValidValues = new Array('3','6','23','33','34',
                               '41','42','43','46',
                               '49','50','52','64');

function isMember(strValue, arrValueList){
 for(var i = 0; i < arrValueList.length; i++){
  if(arrValueList[i] == strValue){
   return true;
  }
 }
 return false;
}

Then you can call your function as per:
Code:
if(isMember(form.elements["state"].value, arrValidValues)){
 ... something here
}

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
What is it that you are trying to achieve?
Exactly what you typed.
Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top