I'm attempting to adjust various variables depending on which button the user clicks. For instance, there are three buttons:
<button id="button1" onclick="isClicked(this.id)">B1</button>
<button id="button2" onclick="isClicked(this.id)">B2</button>
<button id="button3" onclick="isClicked(this.id)">B3</button>
There are also 3 objects:
var button1 = { someValue: 0, otherValue: 5 };
var button2 = { someValue: 0, otherValue: 5 };
var button3 = { someValue: 0, otherValue: 5 };
The ID of the clicked button is passed into the JavaScript function as shown below:
function isClicked(clicked_id) {
selectedID = (clicked_id);
}
My goal is to change the value of a variable based on the clicked button - so if button1 is clicked, modify the button1 object, and if button2 is clicked, update the button2 object.
I have explored resources like Programmatically setting the name of a variable and Programmatically set variable names by appending an ID parameter but I haven't found a solution that fits my situation.
Is there a more effective approach to accomplish this task?