I have a <select>
with 4 <option>
s and I'm trying to get the selected option into a value of a <input type="hidden">
.
Here's my code:
<form id="selector" name="selector" action="" method="get">
<label>Number of players: </label><select form="selector" id="selectelement">
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="hidden" id="numofplayers" />
<label> Board size: </label><input type="number" id="board_size" maxlength="2" style="max-width: 20px;" name="board_size" min="3" max="20" />
<label> Sequence to win: </label><input type="number" id="win_size" maxlength="1" style="max-width: 10px;" name="win_size" min="3" max="9" />
<input type="submit" name="submit" value="Go" />
</form>
I tried this:
function goform()
{
this.form.elements["numofplayers"].value = document.getElementById('selectelement').selectedIndex.innerHTML;
}
and in the form tag i do that:
<form onsubmit="goform()" id="selector" name="selector" action="" method="get">
How do I do that?
Thanks.
EDIT: Sorry, I solved it, appearently you can get the value of a selected option by just doing that:
var x = document.getElementById("selectelement").value;
Thanks anyway.