select all elements of one selection list

G

GiSmo

hello I'm french so I hope I hunderstand your answers ! I'm begginer
in javascript and I would like to do this :

select all elements of one selection list (html) with a javascript
fonction

could you help me ?

thanks lot !
 
L

Lasse Reichstein Nielsen

hello I'm french so I hope I hunderstand your answers ! I'm begginer
in javascript and I would like to do this :

select all elements of one selection list (html) with a javascript
fonction

It requres the select element to accept multiple selected options
(e.g., the tag contains the "multiple" attribute).

Assume "selectRef" refers to the select element:

for (var i=0;i<selectRef.options.length;i++) {
selectRef.options.selected = true;
}

That is, set the "selected" field of each option to "true".

/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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top