Get selectedIndex of combobox and pass to input?

1

In the following example I get the value of the description in the alert; I need to get this text from the drop down box in the value of an input field ... how to adapt this? I have to submit this description via post! Note: I do not want to send the value of the combobox and yes the selectedIndex value, I hope you have understood.

    <script>  
    function desc(){  
    var i = document.form2.cb.selectedIndex;  
    alert(document.form2.cb[i].text);  
    }  
    </script>  

    <form name="form2">  
    <select name="cb" onchange="desc()">  
    <option value="1">VERDE</option>  
    <option value="2">AMARELO</option>  
    <option value="3">AZUL</option>  
    <option value="3">BRANCO</option> 
    </select>  
    </form>
    
asked by anonymous 22.12.2014 / 04:21

1 answer

3

You can fill in a hidden field:

<input type="hidden" name="cbi">
function desc(){  
    var i = document.form2.cb.selectedIndex;  
    document.form2.cbi.value = document.form2.cb.selectedIndex;
} 
    
22.12.2014 / 04:32