I've been trying to get variables to work with drop down options on a page. I was struggling to even get a value out of the function but managed by removing "var" from o1. Now if I type o1 into the js console on chrome i get a value for it but if I set another variable equal to it, such as b1, it comes out as undefined. I'd like to add if statements after the function using its output but they didn't work either. Not sure what i'm doing wrong...
<html>
<head>
<title>Options to variables</title>
</head>
<body>
<form>
Options
<select id="i1" onchange="options()">
<option selected = "true" disabled="disabled">---</option>
<option id="1">Option 1</option>
<option id="2">Option 2</option>
</select><br>
</form>
</body>
<script>
var o1;
function options(){
o1 = i1.options[i1.selectedIndex].id;
return o1;
}
var b1 = o1;
</script>
</html>