Forum Academy Marketplace Showcase Pricing Features

Increment a number using javascript

Hello Bubblers,

I’m trying to increment a number when clicking on a button, and store this value in a input. Its only for front end using. I dont need a database, neither a customstate. I already have a javascript that runs that:

https://jsfiddle.net/sfagmzyx/

What is the best way to implement this on bubble?

The best way to do this in Bubble is custom states.
https://knowcode-tech.bubbleapps.io/version-test/custom_states_increment?debug_mode=true

It couldn’t be simpler. Trying to do it with javascript would be possible but very awkward! :slightly_smiling_face:

1 Like

@lindsay_knowcode Man, your counter is flawless! One question though, where does your “This Button’s count + 1” come from?

Thanks!

“Count” is the custom state that is created on the button. @sollyepics

1 Like

@ankur1 Hi there! I did notice that, thank you. I recreated his method as far as that custom state, but his Value stumped me. His Value is “This Button”. Do you think he named his button “This Button” or do you think that’s Bubble’s way of identifying one of it’s own built-in buttons? I looked for “This Button” in my list of values, but didn’t find anything along that line so wasn’t sure. Thanks friend!

When you add workflow on the button, then Bubble refers to that as “this button”. @sollyepics



[email protected] Nocodetalks
Helping Bubble Devs to build No-Code Products. Follow me on Twitter

1 Like

@ankur1 Ah, good to know. Thanks!!!

1 Like

@ankur1 Sorry, one more question if you don’t mind: Do you think the “State Type” considered multiple entries or no?

If you mean, “State Type” with Custom State, then yes you can store list of data with them.



[email protected] Nocodetalks
Helping Bubble Devs to build No-Code Products. Follow me on Twitter

Awesome, thanks!

1 Like

It would be a very twisted and perverse person who would name a Button “This Button”. :slight_smile:

1 Like

One would think. Only that option isn’t available in my list so made me wonder.

While you’re here, how do you push the changing values to your input?

Thanks

The “initial content” of the input is set to the custom state. This is a really common pattern in Bubble. Custom states are a way of sharing/passing values between elements on the same page.