Display new calculated value in text field

Hi All, I have setup a user input field to collect a number. I have connected this user input (number) into a dataset. I have setup a text field that need to get this user input from dataset and perform simple math (number + 10) and display the new value. Can someone please show me how to do this in Wix? Many thanks.

Hi,

You can use the datasets getCurrentItem() to do that, then multiply the value by 10 and set it to a text component .

Liran.

Thank you Liran, your suggestion is working for me. :slight_smile:

1 Like

Hi Liran,

I tried your suggestion, the solution is working great in the preview mode where the item can be displayed in the text component. However, after published the changes to a live site the page is unable to display the item. Below are the codes I added, do you know whether I need to do anything special to get this working on a live site? Thanks, FM.

$w.onReady(function () {
$w(β€œ#dataset1”).onReady( () => {
let itemObj = $w(β€œ#dataset1”).getCurrentItem();
$w(β€œ#text47”).text = itemObj.terms;
});
});

Hi,

Please see this article for syncing data.

Liran.

Hi Liran,

I tried your suggestion to sync data between my sandbox and live data by copying all items to live. Still having the issue where preview mode is working fine but live site unable to display the item in text component. Any ideas what is not working for the live site? Thanks FM.

Check the collection permissions, maybe their restricted for Admin only.
You can see it at the collection settings button.

Liran.

1 Like

Hi Liran,

Thank you for the suggestion, the problem is related to collection permissions set for Admin only. After the changing permissions the live site is working as expected. Thank you, FM.

Hi all,

I’m doing something similar to above. I’m trying to take a user’s input and use it in a simple equation to return a number. I used the above code but ran into a roadblock. When I submit the form, the text component does not update. Could you please look at my code below and let me know what’s wrong? Thanks in advance.

export function button1_click(event) {
$w.onReady( function () {
populateFields();
})
}

$w.onReady( function populateFields() {
$w(β€œ#dataset2”).onReady(() => {
let itemObj = $w(β€œ#dataset2”).getCurrentItem();
$w(β€œ#gpa”).value = itemObj.terms;
$w(β€œ#chance”).text = itemObj.terms;
});
});

For the time-being, I’m trying to get #chance to show the value in #gpa. Once I figure that out, will try plugging in my equation.