Take combobox selectedIndex and switch to input?

Asked

Viewed 509 times

1

In the following example I take the value of the description in Alert; I need to take this text from the drop-down box in the value of an input field... how to adapt this? I have to send this description via post! Obs: I don’t want to send the value of the combobox but the value selectedIndex, I hope you 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>

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;
} 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.