Trying to create a stopwatch. Running this code on a button click:
var counter = 0;
var isPaused = false;
var t = window.setInterval(function() {
if (!isPaused) {
counter++;
var s = counter;
convertSeconds(Math.floor(s));
}
}, 1000);
function convertSeconds(s) {
var minutes = Math.floor(((s % 86400) % 3600) / 60);
var seconds = ((s % 86400) % 3600) % 60;
if (minutes < 10) {minutes = "0" + minutes;}
if (seconds < 10) {seconds = "0" + seconds;}
$("#minutes").html(minutes);
$("#seconds").html(seconds);
}
I have two fields called “minutes” and “seconds”, if I want to save the JS result to the DB, where do I put the bubble_fn_suffix(x)? And with what variables?
Not sure what you’re asking and I know very little JS.
If you’re asking how to use JS to bubble function to get those two variables’ values back so they’re accessible in a workflow:
Probably need two JS to bubble elements, one for minutes variable and one for seconds? Make them type number if that’s what you need, but bubble will probably drop your leading zeros! So if named slightly different for distinction–using suffix mins and secs, just add to wherever you get those values in your code: bubble_fn_mins(minutes); bubble_fn_secs(seconds);
Then you can use those values in a workflow to add to database: JavascripttoBubble x’s value.
The javascript to Bubble elements you have on your Page with the suffix “mins” and “secs” have you set the data type to “number” because your javascript minutes and seconds variables are set to be integers at the moment
Not infront of a computer at the moment, so I can’t remember clearly but there is a Publish Value checkbox on the JavaScript to Bubble element, make sure that is checked mark as well…
Well… I was too fast. Tested it with only one JS to bubble with the minutes and they never reached a value larger than zero… Marking the “Publish value” did the thing. Thank you!