Forum Discussion
Add number variables without a button
Hi!
I’m trying to create a slide where the learner types in multiple numbers, which all add up to a total displayed at the bottom of the same slide. I want to be able to display the total at the bottom and have that update as the learner enters each number (without needing to click a button to trigger adding the numbers). Using triggers to add the variables to a total variable (displayed at the bottom) works great unless the learner decides to change a number. When this happens, the total continues to add. Thoughts on how I can make this function without a button even if the learner decides to change a number?
Thanks!!
- MichaelHinzeCommunity Member
Add a trigger to set the total variable back to zero, before you recalculate.
- MeganGonzalez-dCommunity Member
Thanks for the reply! I can see how this would work with a button to click to calculate, but how could this work with multiple numeric entry boxes (I have 7) and trying to show the sum of all 7 boxes in real time without a button?
- MeganGonzalez-dCommunity Member
Thanks for the reply! I can see how this would work with a button to click to calculate, but how could this work with multiple numeric entry boxes (I have 7) and trying to show the sum of all 7 boxes in real time without a button?
Hi, Megan!
Are you comfortable sharing your file so we can see what you have so far? You can upload it here or privately in a support case, and we'll be sure to delete it from our systems once troubleshooting is complete.
- WaltHamiltonSuper Hero
Ask yourself, "When do I want the total recalculated?", and there's your answer.
If I were doing what you describe, I think I would want to recalculate when one of the 7 variables changes. There is a trigger "when" for that. Like Michael says, every time any one of the 7 changes, set the total to 0, and add all 7 together.
For a way to create fewer triggers, see the attached sample.
- MeganGonzalez-dCommunity Member
Thanks all! I appreciate the help! I was able to get it to work. I ended up setting up triggers to reset and then calculate all 7 numbers. Unless I'm missing a simpler way to do this, I put all of these triggers on each of the number variables. Turns out part of my issue when working on this was coming up with a NaN error, which I had assumed was because I was doing something wrong. But I guess I needed a condition to only add the variables if the value is greater than or equal to zero to eliminate this error!
- WaltHamiltonSuper Hero
I added the simpler way to my previous post. I got the NaN error because I put a prompt in the input boxes, and it isn't a number. I solved it the same way you did.