javascript - Filling hidden input field from select menu using Js -


i using function:

function selectionchange() {   var e = document.getelementbyid("myselect");   var str = e.options[e.selectedindex].value;   document.getelementbyid('txt').value = str; } 

to fill hidden field when changing options:

<form>   <select id="myselect" onchange="selectionchange();">     <option value="1">sun</option>     <option value="2">moon</option>   </select>   <input type="hidden" id="txt" value="">   <button type="submit">send</button> </form> 

but not work.

the closing tag of < /script> looks bad. not sure if caused editing. have tested code after changing < /script> </script> , worked fine.


Comments