Hello,
I would like to know what is wrong with my code.
I created a content manager whose content comes from members through a form
Except that in the data collected I would like 2 data (values) to multiply between it to give me a result.
And I would like this result to be saved to another text element in the content manager.
Here is my piece of code on which I get the following error:
Wix code SDK error: The text parameter that is passed to the text method cannot be set to the value 1800. It must be of type string.
import wixData from 'wix-data';
import wixUsers from 'wix-users';
function gain(){
var cote = $w("#text62");
var mise = $w("#text63");
function multiplier(){
return cote * mise;
}
return multiplier();
}
$w("#text67").text = gain()
export function dataset2 () {
$w("#text67").text = gain()
}
Cordially
Wix code SDK error: The text parameter that is passed to the text method cannot be set to the value 1800. It must be of type string.
Just as it says: you are trying to put a numeric value into a user element which only knows strings (yes, even if you set input to “Number”, I know, it’s very, very basic).
Try to convert the number to a string before handing it over to the page element with .toString() and then later on, when you write it to the db, convert it back to a number using .parseFloat().
As i mentioned in your other post:
var cote = $w ( “#text62” ).text;
var mise = $w ( “#text63” ).text
Should be
var cote = $w ( “#text62” ).text;
var mise = $w ( “#text63” ).text
Or use Number( $w ( “#text62” ).text)
Please do not post multiple posts on the same subject.
Please only put your code in a code block, not your entire post.
Excuse me, I didn’t do it on purpose …
Hello,
What I would like to achieve is from an X value and a Y value that a user enters in the form (linked to a collection) that a function multiplies its 2 values and sends it to me directly in my collection under the TOTAL value
I try to make a Bankroll Management, but before i try to be this ^^
Cordially
I tried this code based on one of your tutorials, but I didn't get the desired result in my database.
Hello Guéwen Duché,
ok you did understand something wrong. I try to explain one more time.
- Please use CODE-TAGS / CODE-BLOCKS / CODE-SNIPETS to show your CODE, like in this example here… (only CODE in CODE-Block).
I am a CODE-BLOCK! (CODE-SNIPET) and only CODE should be in here.
- Never use a pic to show your code. Anybody will waste his time to retype your CODE from a pic (it’s wasting of time).
So please, show your CODE again in the right way (using a CODE-Block & not a picture).
Thanks.
About your code:
I tried this code based on one of your tutorials, but I didn’t get the desired result in my database.
What are the results of the console.log’s
Does it save any data to the database?
calculGain<- are u sure the name is right? → go to your collections, go to the calculGain column → rightclick and select property’s → check the value of it.
same with BankrollTest. is the name right?
go to your collection and open the settings.
check if the ID is the same as BankrollTest
Kind regards,
Kristof.
import wixData from 'wix-data';
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
function myFunktion (parameter) {
var inValue
let user = wixUsers . currentUser;
console . log(user)
let userId = user . id;
console . log(userId)
inValue = Number (parseFloat($w('#input6') . value)) * Number (parseFloat($w('#input7') . value));
console . log(inValue)
let toSave = {"calculGain": inValue};
wixData . save("BankrollTest", toSave)
.then( (results) => {
let item = results; //see item below
} )
}
Oke then,
Do you use a button to trigger the function :
myFunktion ( parameter )
Where do u use it?
kind regards,
kristof.
Yes I use a “#button5”
To test your code out.
Add a button element.
select te button and at the right side of the code panel you will se the elements property’s.
Go to onClick and select it.
It will give it a name or you can change it and press enter.
a codeblock will be added to the code panel.
inside that codeblock add your function.
So you will have something like this.
yourbutton.onClick((event)=>{
myFunktion(yourParemeter)
})
seemslike you don’t use the parameter so you can leave it empty
also past the code here where you use the button5
kind regards,
kristof.
Ty for your help, i have try your method by add the button
import wixData from 'wix-data';
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
button5 . onClick((event)=>{
function myFunktion (parameter) {
var inValue
let user = wixUsers . currentUser;
console . log(user)
let userId = user . id;
console . log(userId)
inValue = Number (parseFloat($w('#input6') . value)) * Number (parseFloat($w('#input7') . value));
console . log(inValue)
let toSave = {"calculGain": inValue};
wixData . save("BankrollTest", toSave)
. then( (results) => {
let item = results; //see item below
})
} // on this line I got unexpected token i don't know why
import wixData from 'wix-data';
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
button5.onClick((event)=>{
myFunktion()
}
function myFunktion () {
var inValue
let user = wixUsers . currentUser;
console . log(user)
let userId = user . id;
console . log(userId)
inValue = Number (parseFloat($w('#input6') . value)) * Number (parseFloat($w('#input7') . value));
console . log(inValue)
let toSave = {"calculGain": inValue};
wixData . save("BankrollTest", toSave)
. then( (results) => {
let item = results; //see item below
})
}
Remove all and add this.
be sure the button has the event.
Look onto your OPENING and CLOSING - braket.
What do you can recognize?
button5.onClick((event)=>{ //<------opening....
} //<------closing.... ( you forgot ----> ) at the end.
And you also have to do it like this…
$w('#button5').onClick((event)=>{ .... YOUR CODE HERE ... })
or you have first to define your button like this…
var button5 = $w('#button5')
Kristof, did you test the CODE?
button5.onClick((event)=>{ myFunktion() }
Does this work?