I've been trying to figure out how to make it so when someone clicks an option, a variable gets assigned. Here is what I've tried:
function changessw() {
switch (document.getElementById("ssw").value) {
case "1":
var test = "Im A";
break;
case "2":
var test = "Im B";
break;
}
}
document.write(test)
<select name="ssw" id="ssw" onchange="changessw()">
<option value="1">A</option>
<option value="2">B</option>
</select>
The variable only works when I test it in the function. I want to work globally. Any help would be appreciated!