post icon

Javascript Get selected value combo box

Per recuperare il selected value di un menu a tendina (dropdownlist) mediante JavaScript puoi usare il seguente snippet:

<html>
<head>
    <title>Untitled Page</title>
</head>
<body>
 <select id="SelCitta" name="selectCitta">
     <optgroup label="Lazio">
        <option value="1">Roma</option>
     </optgroup>
     <optgroup label="Campania">
        <option value="2">Napoli</option>
        <option value="3">Caserta</option>
     </optgroup>
     <optgroup label="Lombardia">
        <option value="4">Milano</option>
        <option value="5">Pavia</option>
     </optgroup>
    <option value="6">Non ricordo..</option>
    <option value="7">Altra opzione fuori group</option>
  </select>
<br />
<input type="button" value="Mostra Selected Value" onclick="SelValue();" /> 

<script language="javascript" type="text/javascript">
function SelValue(){
    var objCombo = document.getElementById("SelCitta");
    var valore = objCombo.options[objCombo.selectedIndex].value;
    alert("Value: " + valore)}
</script>
</body>
</html>

Download Get_selected_value_combo_box.zip (588,00 bytes)

17 febbraio 2009 @ 19:00

No comments yet.

Leave a comment

Leave a Reply

Are you human? Time limit is exhausted. Please reload CAPTCHA.