i am new with wix code so i need to know how can i use buttons that will increment text with 1 when the user click and then i need the number of clicks to be stored in database and then maker this number the same when the page is reloaded. thanks in advance.
top of page
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
![feature fixed.png](https://static.wixstatic.com/media/3bfa8a_f845e1016b8a49758acdd6edd6610c3b~mv2.png/v1/crop/x_0,y_2,w_852,h_508/fill/w_104,h_62,al_c,q_85,usm_0.66_1.00_0.01,blur_3,enc_auto/feature%20fixed.png)
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
bottom of page
Hello Rajaa,
To do that follow the following steps:
- add a text box with an initial value (ex: 0)
- add a button, and add on click event for the button
-inside the on click function add the code to increment the value of the text
get the value of the text
parse it to integer
add one to it
set the text back to it
-to save the value in the collection use to insert function --here
-to keep the value after refresh save it in the session and set it to the text on page load--here
that's how the code wold look like:
import wixData from 'wix-data'; import {session} from 'wix-storage'; $w.onReady(function () { //if there is a value saved in the session set the text to it if(session.getItem("count")){ $w('#text1').text = session.getItem('count') } }); export function button1_click(event) { //to add one to the original value let count = parseInt($w('#text1').text, 10) + 1 $w('#text1').text = count.toString() //to inset it in the collectin let toInsert = { "title": count }; // insert to collection wixData.insert("myCollection", toInsert) // update session value session.setItem("count", count) }
Best
Massa
thanks a lot massa, but how can i see this data when i create it ?