Esta función javascript permite pre-seleccionar automáticamente una opción en un combo html.
El Código javascript
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;
}
}
Forma de uso
Para llamarla simplemente se debe agregar la siguiente linea debajo del combo , esto hara que se ejecute al cargar la página y seteará el valor por defecto.
<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
Ejemplo
En el siguiente ejem se selecciona la opcion 2
<select id ="idSelect">
<option value="1">opcion1</option>
<option value="2">opcion2</option>
<option value="3">opcion3</option>
</select>
<script>selectInCombo('idSelect','option2')</script>
