Función js que selecciona una opción de un combo select html | ![]() ![]() ![]() ![]() (2.06)views: 831 |
para llamarla simplemente
<script>selectInCombo('idSelect','valor')</script>
idSelect , es el id del elemento select en html
valor , es el valor que se encuentra en los option, no el value, es el valor texto
ejem:
En el siguiente ejem se selecciona la opcion 2
<script>selectInCombo('idSelect','option2')</script>
<select id ="idSelect">
<option value="1">opcion1</option>
<option value="2">opcion2</option>
<option value="3">opcion3</option>
</select>
<!-------------FUNCION--------------->
function selectInCombo(combo,val)
{
for(var indice=0 ;indice<document.getElementById(combo).length;indice++)
{
if (document.getElementById(combo).options[indice].text==val )
document.getElementById(combo).selectedIndex =indice;
}
}
1 2 3 4 5


