Re: Select an Array, to Display
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Select an Array, to Display

From: mick white <mick@mickweb.com>
Date: Tue Jan 31 2006 - 19:38:52 CET

Tyrone Slothrop wrote:

> It is a familiar story. It works in Firefox, but not in IE.
>
> I want to dynamically populate a select box with an array of values
> based upon the value selected from another select. The arrays are
> defined when the page is loaded.
>
> Assuming that the arrays are name a, b. and c:
>
> <select name="someArray">
> <option onclick="selArr(a);" value="a">A</option>
> <option onclick="selArr(b);" value="b">B</option>
> <option onclick="selArr(c);" value="c">C</option>
> </select>
>
> function selArr(whichArr) {
> var optStr;
> var cnt = whichArr.length;
> for (var i=0; i<cnt; i++) {

function selArr(whichArr){
var cnt = whichArr.length,
sel=document.forms[0].sel2.options,sel.length=0,i;
for(i=0;i<cnt;i++){
sel[i]=new Option(whichArr[i],whichArr[i])
}
}

>select name="someArray" onchge="selArr[this.value);">

> this.value is treated not as the defined array but as a var value, as
> if is enclosed by quotes.
>
> Any ideas how to get around this?

onchange="selArr(window[this[this.selectedindex].value]);
// provided the arrays are global in scope

[...]
Mick
Received on Tue Feb 7 21:29:03 2006