impostare il valore della SELECT all'indice che contiene una certa parola

S

SAN CAZIANO

selezionare il valore di una SELECT sapendo il testo che deve avere tra le
sue opzioni

<select name="combo">
<option>nome</option>
<option>cognome</option>
<option>prova</option>
<option>forse</option>
</select>


come faccio a impostare il valore della SELECT all'indice che contiene la
parola FORSE
 
M

Martin Honnen

SAN said:
selezionare il valore di una SELECT sapendo il testo che deve avere tra le
sue opzioni

<select name="combo">
<option>nome</option>
<option>cognome</option>
<option>prova</option>
<option>forse</option>
</select>


come faccio a impostare il valore della SELECT all'indice che contiene la
parola FORSE

I am guessing that you want to set the value of the option that has as
its text the string 'forse':

function findOptionByText (select, optionText) {
for (var i = 0; i < select.options.length; i++) {
if (select.options.text == optionText) {
return select.options;
}
}
return null;
}

var option = findOptionByText(document.forms.formName.elements.combo,
'forse');
if (option) {
option.value = 'Kibology';
}
 

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
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top