Get the value of the selected item in a ComboBox in classic asp

4

I have two combobox, I need to get the id of one to load the other from the item that was selected in combobox1, how could I do this through a javascript function.

<select id="cb_catinsumo" class="combo" name="cb_catinsumo" class="combo2">
    <option value="">Selecione uma categoria</option>
    <%monta combo de categoria de insumos sSQL="SELECT categoria_insumo FROM tb_catinsumo ORDER BY categoria_insumo" oQueryCatInsumo.Open sSQL, oConexao IF NOT oQueryCatInsumo.EOF THEN oQueryCatInsumo.MoveFirst DO until oQueryCatInsumo.EOF%>
        <option value="<%=oQueryCatInsumo(" categoria_insumo ").value %>">
            <%=oQueryCatInsumo( "categoria_insumo").value %>
        </option>
        <% oQueryCatInsumo.MoveNext LOOP ELSE %>//sem categorias cadastradas
            <option value="">NÃO HÁ CATEGORIAS CADASTRADAS</option>
            <% END IF %>
</select>
    
asked by anonymous 23.04.2014 / 19:54

1 answer

16

When your combobox is mounted it will look something like this:

<select id="cb_catinsumo">
  <option value="1">item1</option>
  <option value="2" selected="selected">item2</option> /*atente que aqui o item está selecionado*/
  <option value="3">item3</option>
</select>

Below the javascript code for capturing VALUE and TEXT:

1) RECOVER THE VALUE OF THE SELECTED ITEM

var e = document.getElementById("cb_catinsumo");
var itemSelecionado = e.options[e.selectedIndex].value;

2) RECOVER THE TEXT OF THE SELECTED ITEM

var e = document.getElementById("cb_catinsumo");
var itemSelecionado = e.options[e.selectedIndex].text;

There are other ways to capture the values, but this one believes that it fully meets your needs, it has quicker forms, for example with jQuery, if you do not know of one that is researched since it is much more productive in some situations. >     

23.04.2014 / 22:43