There are many ways to do this.
One way is to create an array like object to hold the current selection and then update the text with the items of the array.
We can do this with your example using a couple of premises,
We want to be able to click both frame and angle buttons to give a complete selection.
We want the user to be able to change the selection.
We want the text to always display the current selection.
Changes to your example.
We first give each frame button the same class name. In this case we add the class frame to the class field in the identity Inspector.
We do the same for all the Angle buttons, we give them all the same class angle
We do this so when the button is clicked we will know which class of button has called the single Hype function we have assigned to all buttons. ( yes assign the same function to every button )
Here is the function.
if (! window.selectionList){window.selectionList = {"frame": "", "angle" :""}}
if (element.classList.contains('frame')){
window.selectionList.frame = element.innerHTML
} else if (element.classList.contains('angle')){
window.selectionList.angle =element.innerHTML
}
demo = hypeDocument.getElementById("demo")
demo.innerHTML = window.selectionList.frame + window.selectionList.angle;
Lets break it down.
Firstly any variables we assign with the prefix window is us just making the var global and persistent for the session
if (! window.selectionList){window.selectionList = {"frame": "", "angle" :""}}
We need to create a persistent global var that will hold the selection details. This will be named window.selectionList
We must have window.selectionList declared before we can run any other code to check it. So we check to see if it exists already.
If it did not and we tried to query it we would get an error.
This IF clause allows us to check the var it exists already.
If it does not ( (! operator = not ) , which it will not when the function first runs then we declare it and then store the basic info into it. From then on this type of var will persist.
The type of info/data we use for the var is an Array like object or named array. These type of arrays use keys as the item names and values as the as the keys value.
{key: value}
We can then get to the value by using it’s key.
So in this case if we want to get the frame value we call to the variable window.selectionList and the key frame
window.selectionList.frame
So now we have the Array structure sorted and declared we can now use those class names we assigned to the buttons.
We check the class of button that called the function.
if (element.classList.contains('frame')){..
This is pretty much self explanatory.
If the class list ( an element can have any number of class names assigned to it ) contains a class name of ‘frame’ Then we do something.
If it contains ‘angle’ we do something else.
else if (element.classList.contains('angle')){..
This is where we can now use the keys in the Array like object that has been assign to the global persistent var.
We can set the values to the correct key.
window.selectionList.angle = element.innerHTML
Once we have figured that out, all we then need to do is update the text box with both values for both keys.
demo = hypeDocument.getElementById("demo")
demo.innerHTML = window.selectionList.frame + window.selectionList.angle;
Only the key value that is changed will be updated. the key value of the array that is not changed will persist from the previous selection.
Now even if the user re-clicks one of the buttons, only the value for the new selection will be changed but both current selections will be updated the the text filed.
Example project.
configure.hype 2.zip (186.2 KB)