javascript - Set variable value from input before submit -
javascript - Set variable value from input before submit -
first, have input in form.
<select id="entry_14"> <option value="woman">woman</option> <option value="man">man</option> </select> then declared variable.
var mygender = document.getelementbyid('entry_14').value; but then, when document.write, shows "man" before user makes selection, , after selecting woman, still shows man.
how can set value of variable change, each time user selects 1 of options?
it executes because code not in function. need phone call function when select changes. add together onchange handler select. in illustration pass this.value select lists value function. can whatever want value.
<select id="entry_14" onchange="myfunction(this.value);"> <option value="woman">woman</option> <option value="man">man</option> </select> <script> function myfunction(val) { document.write(val); } </script> javascript forms variables option
Comments
Post a Comment