I'm trying to get the dropdown to change the textbox, but seem to be having issues.
<head>
<title>DropDown</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="generator" content="Geany 0.20" />
<script type="text/javascript">
function chkind() {
var dropdown1 = document.getElementById('dropdown1');
var textbox = document.getElementById('textbox');
var a = dropdown1.options[dropdown1.selectedIndex];
if(a == 0){
textbox.value = "hi";
} else if(a == 1) {
textbox.value = "bye";
}
}
</script>
</head>
<body>
<select onchange="chkind()" id="dropdown1">
<option>Hi</option>
<option>Bye</option>
</select><br />
<input id="textbox" type="text" />
</body>
Probably just:
var a = dropdown1.selectedIndex;
if you're trying to check that the zeroth option is selected.
Either that, or give your options values in the HTML and check the values themself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With