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.
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
Bonjour Kemel, visiblement tu es français vu ton site. Quel est le code utilisé finalement ?? Je veux exactement la même chose que ton site ! :-) Merci !
Ok i just understand why
Thanks You Shlomi
Just for untersdant, why you choose "#dataset1" and not "#Base" ?
Kemel
Hi Kemel,
we need to use the following code:
export function recalc6(event, $w) { var sum = 0 if($w('#input1').value) sum += parseInt($w('#input1').value); if($w('#input2').value) sum += parseInt($w('#input2').value); if($w('#input3').value) sum += parseInt($w('#input3').value); if($w('#input4').value) sum += parseInt($w('#input4').value) if($w('#input5').value) sum += parseInt($w('#input5').value) $w("#input6").value = sum; $w("#dataset1").setFieldValue("billetTotal", sum); } export function recalc7(event, $w) { var sum = 0 if($w('#input1').value) sum += 5*parseInt($w('#input1').value); if($w('#input2').value) sum += 10*parseInt($w('#input2').value); if($w('#input3').value) sum += 20*parseInt($w('#input3').value); if($w('#input4').value) sum += 50*parseInt($w('#input4').value); if($w('#input5').value) sum += 100*parseInt($w('#input5').value); $w("#input7").value = sum; $w("#dataset1").setFieldValue("amount", sum); } export function recalc(event, $w) { recalc6(event,$w); recalc7(event,$w); }
Shlomi
Shlomi any idea why i have the red line in dataset?
Have make this code after your code but is not working
all input go to the data with dataset only 6 ans 7 don't want
I have to line red
export function button1_click(event, $w) {
let toInsert = {
"Number": $w("#input6").value ,
"Number": $w("#input7").value ,
};
$w.wixData.insert("Base", toInsert)
.then( (results) => {
let item = results;
} )
.catch( (err) => {
let errorMsg = err;
} );
}
Hi Kemel,
please share the code you are using and let me know if you have any question you can use help with
Shlomi
I'm triying this but is not working
https://www.wix.com/code/home/forum/questions-answers/how-to-insert-a-data-in-two-collection-from-a-form
Hi Shlomi,
Yes i saw the link, i m trie but i dont where to put the code in to your code and how sorry. I will trie again but i need the solution before wednesday.. anyway i will use a calculator app
Thanks you for your help
Kemel
Hi kemel,
in the previous answer i have attached a link to the reference documentation with example how to do it. did you read it? this scenario is a bit tricky and assumes you have some coding experience or the ability to learn from code samples
Shlomi
And how i will use insert? Sorry but i m very novice..
Hi kemel,
right this is out of the scope of the original question you have asked, you will need to implement an onclick event on the page button to use wix data insert of the values to the db
Shlomi
But one problem the Input 6 et 7 don't go to the database after i submit
Thanks!!!!
Hi Kemel,
please use this code below, for each of the inputs 1-5, call the recalc function on the input 'onchange'
export function recalc6(event, $w) { var sum = 0 if($w('#input1').value) sum += parseInt($w('#input1').value); if($w('#input2').value) sum += parseInt($w('#input2').value); if($w('#input3').value) sum += parseInt($w('#input3').value); if($w('#input4').value) sum += parseInt($w('#input4').value) if($w('#input5').value) sum += parseInt($w('#input5').value) $w("#input6").value = sum; } export function recalc7(event, $w) { var sum = 0 if($w('#input1').value) sum += 5*parseInt($w('#input1').value); if($w('#input2').value) sum += 10*parseInt($w('#input2').value); if($w('#input3').value) sum += 20*parseInt($w('#input3').value); if($w('#input4').value) sum += 50*parseInt($w('#input4').value) if($w('#input5').value) sum += 100*parseInt($w('#input5').value) $w("#input7").value = sum; } export function recalc(event, $w) { recalc6(event,$w); recalc7(event,$w); }
Hi Karson,
when 'adding' to strings, Javascript code will concatenate them, so '10' + '20' will become '1020'
what you want to do is concatenate to integers 10 + 20 => 30
please have a look here: (btw, this is plain old javascript, not wix related :) )
export function submitCalc_click(event, $w){ var a = parseInt($w("#input1").value); var b = parseInt($w("#input2").value); var n = a + b; console.log(n); }
good luck,
Shlomi
I have a similiar question. My code is below. If it is terrible, I apologize. I am very new to this. I also tried parseFloat for what it is worth. I don't actually know their distinctive use cases, but it did not help me. Console shoots out the two inputs, but not doing the math. Input 1 = 10 and Input 2 = 20 it outputs 1020, not 30. I appreciate the help!
export function submitCalc_click(event, $w){
var a = String(parseInt($w("#input1").value));
var b = String(parseInt($w("#input2").value));
var n = a + b;
console.log(n);
}
kemelhaidar.wixsite.com/monsite
hi,
please share your wix code site with the issue you described, ill have a look
Shlomi
Hello Shlomi, thank for your help,
In the form i have 3 input and one button for submit to the data the 3 input
Input1 and input2 its for whriting number only default 0
and input3 its the sum Input1 and input2
i need the code java
if you want i can built a site for that
thanks you
kemel