Help with JavaScript to Bubble

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?

Thanks in advance

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.

Thanks @meyerhd2 for your reply.

I don’t know any JS, the above code is taken from the internet.

I think so too. This is what I have now but still not working:

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);
bubble_fn_mins(minutes); 
bubble_fn_secs(seconds);

}
1 Like

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…

Thanks @shawn.chaudhery for your reply.

The data types are numbers, yes.

Can you share a screen shot of the javascript to Bubble element options?

Of course:

When I marked “Publish value”, nothing happened. The default value (0) is displayed.

What value do you get in your chrome browser console log? You can check by adding:

Console.log(minutes);
Console.log(seconds);

In your script right after the bubbl_fn() lines

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!

JStobubble opens the floodgates

It really does

This topic was automatically closed after 70 days. New replies are no longer allowed.