|
-
Why does eval() make a difference to this code snippet?
Hi,
I am trying to populate a combobox(ComboCities) to display cities dependant on the selection of another combobox (ComboCountries).
Since the list of countries come from a database, and expand over time, I want to use the CountryID-value to determine which array must be read to
populate the ComboCities.
Currently I do the following:
//populating country data
countries="England|France|Germany";
countriesID="1|2|3";
//loading all cities: note-> every arrayname contains the countryID
cityname1="London|Leeds|Liverpool|Glasgow";
citiesID1="11|12|13|14";
cityname2="Paris|Lyon|Marseille|Lille";
citiesID2="15|16|17|18";
//function to populate the ComboCities
function getcities ()
{
countryid=CombCountries.getValue();
ComboCities.removeAll();
NewIDs="citiesID"+countryid;
NewName="cityname"+countryid;
listcityids=NewIDs.split("|");
listcitynames=NewName.split("|");
for (i=0; i<listcityids.length;i++) {ComboCities.addItemAt(i,listcitynames[i], listcityids[i]);}
}
Somehow the arrays 'listcityids' and 'listcitynames' are not created. I found a workaround that will create these arrays by
changing the following codepart:
NewIDs=eval("citiesID"+countryid);
NewName=eval("cityname"+countryid);
So my question really is:
Why I had to use the eval() function for this?(why does it technically changes the logic of the code)
I hope someone can explain it, because I had to add code, without knowing the true purpose.
Kind regards
Patrick
Last edited by cuboctahedron; 11-20-2002 at 06:16 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|