select

A

Alexandre Laplante

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...
 
L

Lasse Reichstein Nielsen

Alexandre Laplante said:
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,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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,077
Messages
2,570,566
Members
47,202
Latest member
misc.

Latest Threads

Top