I want to percentage calculation for progress bar.
There are Target, Current value, and Current percentage.
600 is current value calculation from wix database.
1000 is The Target just text.
NaN% is the Current percentage I want to display.
I want to
1 Display the current percentage.
2 Connect to progress bar
my code for 1 is...
$w.onReady(function () { // Write your JavaScript here $w("#text11").text = (Number($w('#text12'))) / (Number($w('#text10'))) * 100 + "%"; // Click "Preview" to run your code });
This code not work. Display NaN%
Someone please help me.
Does anyone know?
Hi nanami,
You need to take the .text property of the text boxes in your calculation, rather than the text box object itself.
$w('#text11').text = ( ( Number($w('#text10').text) / Number($w('text12').text) ) * 100 ) + "%";
Your calculation for percentage is also backwards, based on what you've given us. I would highly suggest giving your objects useful names to avoid confusing yourself. Also, breaking up long lines into the math portion and the text portion may help.
Something like this would be much more readable, in my opinion.
let value = Number( $w('#ValueText').text ); let target = Number( $w('#TargetText').text ); let percent = 100 * ( value / target ); $w('#PercentText').text = percent.toString() + '%';