Hi guys so i am trying to change the value of a javascript variable depending on what button is selected. For example
<button id="1" onclick="changeVal('val1')">b1</button>
<button id="2" onclick="changeVal('val2')">b2</button>
<script>
var value;
function changeVal(choice) {
if (choice == 'val1') {
value = 'number value 1'
} else if (choice == 'val2'){
value ='number value 2'
}
*etc for more buttons*
}
</script>
The variable value will then be used later on. Can't really wrap my head around the problem, im either doing it completely wrong or so close but can't quite get there.
edit: So still having trouble, basically i want to return that choice value so it can then be called in another function e.g.
<script>
var value...
function changeval... //Return choice value out
function useValue() {
alert(choice) //Use choice value here
}
note ignore syntax wrote quickly.
valuevariable not assigned to the value that you want?