By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,380 Members | 1,646 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,380 IT Pros & Developers. It's quick & easy.

select

P: n/a
Est-il possible en javascript de modifier les OPTION d'une balise SELECT a
partir d'un autre..? Donc la selection d'un premier choix changera la liste
du deuxieme.

Merci Alex...

Is this possible in javascript to modify the OPTION of an SELECT from an
other one..? So the first selection change the second option list.

Thank Alex...
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Alexandre Laplante" <al*******@avior.ca> writes:
Is this possible in javascript to modify the OPTION of an SELECT from an
other one..? So the first selection change the second option list.


Yes.
You can trigger on the change to the first select element using the
onchange event handler. You can then change the contents of the second
select element from this handler.

To change all the options of a select element (here referenced by
selectRef), you can do something like

var newOptions = ["option1","value1","option2","value2"];

var optsRef = selectRef.options;
while (optsRef.length > 0) { // Delete the current options
selectRef.remove(optsRef[0]);
}
for (var i=0;i< newOptions.length;i+=2) {
selectRef.add(new Option(newOptions[i],newOptions[i+1]),null);
}

That is, use "selectRef.remove" to remove an option and
"selectRef.add(new Option(text,value),null)" to add a new option.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
yep :P
"Alexandre Laplante" <al*******@avior.ca> wrote in message
news:%n********************@nnrp1.uunet.ca...
Est-il possible en javascript de modifier les OPTION d'une balise SELECT a
partir d'un autre..? Donc la selection d'un premier choix changera la liste du deuxieme.

Merci Alex...

Is this possible in javascript to modify the OPTION of an SELECT from an
other one..? So the first selection change the second option list.

Thank Alex...

Jul 20 '05 #3

P: n/a
> Est-il possible en javascript de modifier les OPTION d'une balise
SELECT a partir d'un autre..? Donc la selection d'un premier choix
changera la liste du deuxieme.


Pour un exemple :
http://www.rgagnon.com/jsdetails/js-0033.html

Bye.
--
Real Gagnon from Quebec, Canada
* Looking for Java or PB snippets ? Visit Real's How-to
* http://www.rgagnon.com/howto.html
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.