Hi Harry,
Thanks for asking. Glad to help.
If I understood you correctly, you read what Brian Bishop and I exchanged and it is not clear enough. Let me try to explain better. But first, I’ll quote myself:
Your function is not like mine which is called to modify data and return data. You may undestand better with this:
export function total(event) {
var Total;
...
Total = formatNumber(total);
$w("#input120").value = Total;}
function formatNumber(num) {
return "$" + num
.toFixed(2)
.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");}
You must first to add the function formatNumber in your code. It can be placed anywhere you want in your code exept inside of an another function. I prefer to put it at the very end, because, once it’s tuned like I want it, it’s useless to see it always when I look at my code.
Second, you neet to decide how you want to use formatNumber. You can use it indirectly or directly. What I mean by that is:
-
Indirectly: Y ou use a variable to keep your number and you convert it to the end with the function. Then you pass the contents of the variable to your field, as in my example.
-
Directly: You pass the formatNumber function to the input field and place your calculation as an argument to the function. Here’s an example using what you wrote:
// For full API documentation, including code examples, visit https://www.wix.com/code/reference/
$w.onReady(function () {
});
export function button555_click(event) {
console.log("button has been pressed");
$w('#input9').value = formatNumber(Number($w('#dropdown3').value) + Number($w('#dropdown4').value) + Number($w('#dropdown5').value)+ Number($w('#dropdown6').value) + 75);
console.log("calculation finished");
}
function formatNumber(num) {
return "$" + num
.toFixed(2)
.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");}
As you can see, I did not put anything inside $w.onReady(function () {});. That’s because what you want to do is, if I understand correctly, click on a button to perform a calculation and a conversion. The function called by clicking can not be inside $w.onReady(function () {});. It was a mistake as by default Wix put functions outside $w.onReady(function () {});. Better do like Wix.
Other error, you missed semicolons after your console.log();. You may also have another error here with :
$w('#input9').value = (Number($w('#dropdown4').value) + Number($w('#dropdown3').value) + Number($w('#dropdown5').value)+ Number($w('#dropdown6').value) + 75.00);
The program may understand that you use strings instead of numbers just because of the “” +. I prefer not to add .00 after a number, but it’s up to you.
You putted $w(“#input9”).value = 75; inside $w.onReady(function () {});. I don’t know if it really works, but I prefer to put the default value in the page layout instead of using code. And you do not use that value in your calculation but a number, here 75.
I hope this will help you. Have a nice day!
Jonathan