Hello guys,
I need help to get the average of the fields in my survey, as much as possible taking the input data fields and showing it in the same survey before sending, like a calculator. Thanks a lot.
Hey!
Using the radio button’s options you can set a value to each one of the component choices.
After gathering the values of all the checked choices you can use simple math logic in order to present the average of the user’s input (sum up the values - divide by the number of the values).
Note that the value of the radioButton is of type ‘string’ and so if you decide to assign numbers to the value of the component you should use the method Number( ) in order to calculate.
Hope it helps.
Doron.
Thanks!
I’ll try it.
Have a nice day!
Hello There!
I already have the solution for get average in the form without database , the steps that I followed were these:
- Set up the value on the radio button and writte some code to display it in the form.
$w.onReady(function () {
$w('#Nouno').text = $w('#VisionResp').value;
$w('#Nodos').text = $w('#OrientacionResult').value;
$w('#Notres').text = $w('#CompTecResp').value;
});
export function VisionResp_change(event) {
$w('#Nouno').text = $w('#VisionResp').value;
}
export function OrientacionResult_change(event) {
$w('#Nodos').text = $w('#OrientacionResult').value;
}
export function CompTecResp_change(event) {
$w('#Notres').text = $w('#CompTecResp').value;
}
- Get the average of the results in the Text Boxes (#Nouno, #Nodos, #Notres) and display it int the survey (#NoPromedio). First Sum them, then divide by the total of questions (3).
Example:
$w('#NoPromedio').text = String((Number($w('#Nouno').text) + Number($w('#Nodos').text) + Number($w('#Notres').text)) / 3);
}
- Then I personally converted the decimals to 1 (can be 2,3,4,5,6…)
In the same previous example, i changed the code and replaced “String” by “parseFloat” and add “.tofixed(1)”. This (1) is the total decimals you want to show.
Example:
$w('#NoPromedio').text = parseFloat((Number($w('#Nouno').text) + Number($w('#Nodos').text) + Number($w('#Notres').text)) / 3).toFixed(1); }
- Then when compiling everything would look something like this…
export function VisionResp_change(event) {
$w('#Nouno').text = $w('#VisionResp').value;
$w('#NoPromedio').text = parseFloat((Number($w('#Nouno').text) + Number($w('#Nodos').text) +
Number($w('#Notres').text)) / 3).toFixed(1);
}
export function OrientacionResult_change(event) {
$w('#Nodos').text = $w('#OrientacionResult').value;
$w('#NoPromedio').text = parseFloat((Number($w('#Nouno').text) + Number($w('#Nodos').text) +
Number($w('#Notres').text)) / 3).toFixed(1);
}
export function CompTecResp_change(event) {
$w('#Notres').text = $w('#CompTecResp').value;
$w('#NoPromedio').text = parseFloat((Number($w('#Nouno').text) + Number($w('#Nodos').text) +
Number($w('#Notres').text)) / 3).toFixed(1);
}
This work for me, and i dont know nothing about programing, just learn in internet, hope that someone else can help this contribution.
Cya