May 13, 201214 yr Hi all, What I'm trying to do is set the value of the user-selection from the box as a global variable that I can use outside of the function. I think the code below should work but it doesn't.... any ideas? <script> var c1; function countryfunc(val) { c1=val; } document.getElementById('output').innerHTML = c1; </script> <div id="output"></div> <select name="select" id="select" onchange="countryfunc(this.value);"> <option value="16">Spain</option> <option value="15">Germany</option> <option value="14">Netherlands</option> <option value="13">Portugal</option> </select> Thanks a lot in advance! Edited May 13, 201214 yr by nuksies
May 25, 201214 yr In the first place stop spam the forum, just wait for an answer! I will give you an example <select id="leaveCode" name="leaveCode"> <option value="10">Annual Leave</option> <option value="11">Medical Leave</option> <option value="14">Long Service</option> <option value="17">Leave Without Pay</option> </select> You can use this JS: function setSelectValue (id, val) { document.getElementById(id).value = val; } setSelectValue('leaveCode', 14); Cheers
Create an account or sign in to comment