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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Equivalent to ListFind() 1

Status
Not open for further replies.

mattquantic

Programmer
Joined
Mar 28, 2004
Messages
196
Location
GB
Hi. I am using a dropdown list to dynamically populate another dropdown lost from an array.

Very simple. It just loops trough the array, if the value of the selected element from the 1st dropdown matches a condition - an element is added to the second dropdown.
EG: Selecting a country from the first dropdown and having it's cities dynamically populated in the second.

I've done this loads and loads before and it works great.

However, at the moment I'm having to make it so that the first dropdown can have multiple selections.

So the script that loops through the array and populates the second dropdown can use and '=' condition as the value of the first dropdown could be '1,5,7' (rather than '1' or '5' or '7'.

For my loop how for I say:

if(secondvalue is in the list (1,5,7)){}

Please let me know if you know what I mean...

M@)
 
Sometimes, I create a String like:

Code:
s += "*"+val+"*";

...which leads me to something like s = "*3**5**7*".

Then, to search the list, I just:

Code:
if(s.indexOf("*"+valOfInterest+"*") > -1)
{
 //whatever
}

A little crude, but gets the job done.

Obviously, if you have the "okay" values in an array, you can cycle through them and check each one for compatibility.

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Hi. I have the example working. Now to get it working for my lists.

The issue I think is that the value of 's' would be the current value of the dropdown list, which is formatted like this: 1,2,3

If there is a method of dynamically changeing 1,2,3 into *1**2**3* then I'm in business.

M@)
 
If you actually have a string like "1,2,3", then you can:

Code:
if([red](","+s+",")[/red].indexOf(","+valOfInterest+",") > -1)
{
 //whatever
}

If you just search for val+",", then you might get a hit for "3" when the list contains "23" (for example). By putting the commas at the start and finish, you set common delimeters for before and after every entry in the list.

Does that help?

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top