This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Dreamweaver > October 2005 > Re: javascript: need to select a value in select list based on value





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: javascript: need to select a value in select list based on value
Mick White

2005-10-31, 6:27 pm

RobGT wrote:

> Sorted it, thanks anyway :)
> If anyone else needs it...
>
> for (optionCounter = 0; optionCounter < frmCountry.length; optionCounter++)
> {
> varListValue = frmCountry.options[optionCounter].value;
> if (varListValue==) {
> frmCountry.options[optionCounter].selected=true;
> }
> }

Looks to be IE only. Note the need to reference the form.



with(document.forms[0]){
for (var optionCounter = 0; optionCounter < frmCountry.length;
optionCounter++) {
frmCountry.options[optionCounter].selected=
(frmCountry.options[optionCounter].value==hidCountry.value);
}
}

Mick
--
Isn't it enough to see that a garden is beautiful without having
to believe that there are fairies at the bottom of it too?
[Douglas Adams]
Mick White

2005-10-31, 10:22 pm

RobGT wrote:

> Hi Mick,
> Not sure I follow what you said there?
>
> In my answer post I missed the fact that my variables to collect form
> element info are pre-set earlier in my script code, like this:
>
> var frmCountry = document.getElementById('country');
>
> Is my code still ok, or should I change it over?


This is OK, but the forms collection works on more browsers.

var frmCountry = document.forms["formName"].elements["country"];


>
> for (optionCounter = 0; optionCounter < frmCountry.length; optionCounter++)
> {


//If this loop is within a function, I would use:
var o=frmCountry.length
while(o--){with(frmCountry.options[o]){
selected=(value==hidCountry.value);
}
}
Mick


--
Isn't it enough to see that a garden is beautiful without having
to believe that there are fairies at the bottom of it too?
[Douglas Adams]
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews