I want to take 2 textbox values loaded from DB and total them in another box on page load.
Hey Trailraidersofswfl!
What seems to be your trouble?
If you have text components already connected with those values, you can use their text
property:
let value1 = $w("#textElement1").text // "Text Value"
let value2 = $w("#textElement2").text // "Text Value"
$w("#targetTextElement").text = value1 + " " + value2 // "Text Value"
You can read more about it here https://www.wix.com/code/reference/$w.Text.html#text
Let me know how this worked out for you,
J.
yes it did but, say my txtbox1 value is 100 and txtbox2 value is 200 the answer comes out as 100 200, so now I need to figure out how to get their # values to add up. Sorry I am new to Javascript so kind of learning as I go.
No problem!
The simplest way would be to use the parseInt javascript function:
parseInt("17", 10) = 17
The second argument is the base, just always use 10 there.
So you’d fix the previous example with something like:
let value1 = parseInt($w("#textElement1").text, 10)
Let me know how that works out for you.
Thanks,
J.
Yes thank you, i finally got it working but now the total field (Answer) will not send the value in the textbox to the database. The Answer label is connected to the database but the only way it will save to the database is if i manually type in the field. How the form works is the member can change values by selecting yes or no then I have placed a get total button that adds all the fields up for a total then the submit button sends all the changes to the DB. When I go to the DB all the changes are there except the field that is to hold the total point value. The code below is how I am getting my total. It is almost like the total is there but looks blank to the DB.
export function button2_click(event, $w) {
let val1 = parseInt($w(“#value1”).value, 10)
let val2 = parseInt($w(“#value2”).value, 10)
let val3 = parseInt($w(“#value3”).value, 10)
var ans = val1 + val2 + val3
$w(“#answer”).value = String(ans);
}
Hi,
If you wish to update the value in the collection, you should use the update function (Wix Data API) to update a certain record. Note that in order to update this record, you should have an " _id " property of the toUpdate object (as can be seen in the example of the documentation).
Best,
Tal.
Hello,
I have created my own HTML page but I need to simulate a click event once the page loads. My element has an id and my javascript is window.onload=function, and clicks the button correctly BUT it does not work anywhere I put it on the page. I tried Head, beginning of body, end of body. Note, on my HTML page I put all the HTML and SCRIPT under a huge DIV then pasted into the wix html code box. Can I use inside wix html code box? Would work? Anyone tried this?
Thanks
Ed