I have written a simple HTML page where, on a button click event, the selected value from a drop down is printed in a textbox. I have used javascript for this task. I don't know why it's not working, though the logic seems ok to me. Any help would be appreciated.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sample</title>
</head>
<body>
<table align="center">
<tr>
<td>
<select id="drpdwn" name="drpdwn">
<option selected>Select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="text" name="textbox" id="textbox">
</td>
</tr>
<tr>
<td>
<button onclick="myFunction()">Go</button>
</td>
</tr>
</table>
<script>
myFunction() {
var el = document.getElementById("drpdwn");
var sel_value = el.options[el.selectedIndex].value;
document.getElementById("textbox").value = sel_value;
}
</script>
</body>
</html>
queryselectorcall would do the trick without the overhead of a third party js file$(...).click). jsfiddle.net/2mhftb6n