Hello, I currently have a form where users can purchase a service and at the end of my form i have it where the user clicks a button and once they click this button it should change a text element i have set tot the total. The code im using right now is below. Could someone explain why the page does not display the total. Thanks in advance.
Code:
P.s there are no errors in the code in the editor. It just wont display the total.
export function occurance_click($w) {
var y = $w("#text38");
var z = $w("#text39");
var m = $w("#text40");
var x = m + y + z ;
$w("#amount").text = x;
}
If you have an alternative method to do this that would be great too. Once again thanks.
export function occurance_click($w) {
var y = $w("#text38").value;
var z = $w("#text39").value;
var m = $w("#text40").value;
var x = m + y + z ;
$w("#amount").text = x;
}
Tip: Use console log to make sure the value you are trying to grab is valid.
The values that it is trying to grab are just numbers that’s what i dont understand but I have since tried the above fix and the console has continued to return this error.
TypeError: $w is not a function. (In '$w("#acre")', '$w' is an instance of t)'
I really have no idea what would cause this. Any help would be appreciated. Thanks again.
Are you getting the values from a normal text element?
If so, use the following code to switch between integers and strings.
export function occurance_click($w) {
var y = Number($w("#text1").text);
var z = Number($w("#text2").text);
var m = Number($w("#text3").text);
var x = y + z + m ;
$w("#amount").text = String(x);
}
Thanks for all the help i found the error…i wasnt defing the function i was putting the function inside the onclick code. So i made a fucntion added the above code and onClick i called the function… Easy mistake i was missing thanks for help.
Sorry i am just seeing this @ Digital Spark.Co and @shan!
i never actually found the perfect solution to what i wanted so i just kind of rigged something up …
The way i ended up doing it was i set the check box to a value that would equal the cost of that item eg (check box: medium = 4, check box : blue = 6) then on the page i had the three (the number of options i had) different text boxes that i connected to that data (the check boxes or drop down menus) so that when someone would click that box it would set that text equal to the value we set it as (such as 4). I then went ahead and hid all three of those boxes so the user would not see them then i added a new text that equal the total cost i then set up a function that would execute once the user hit next and it would add all of those text boxes up and set the ‘total’ text to the number that they added up to… (i did it all this way bc it wouldnt let me just add up checkboxes and drop down menus that might have changed)
you would first need to create the different pieces of text and note the name of them and fill in the code below as needed.
(i also had the total box hidden until the user hit next…
function add() {
var y = Number($w("#text47").text);
var z = Number($w("#text46").text);
var m = Number($w("#text48").text);
var x = +y + +z + +m ;
$w("#amount").text = String(x);
$w("#amount").show();
you would need to do an onclick command that would call this function of course. eg…
export function next_click() {
add();
}
My situation and website was very specific and rigged up (in terms of the backend code) but it all worked and i was the only one that had to see the backend and it worked for me… I know this isn’t the perfect solution but maybe it could help you come up with a creative way to fix yall’s problems.
… Ik this is all might sound crazy but i hope it helps!!!