I've used ES2 to create a user entry form. On that form there are 12 questions and each question has a radio button with a scoring system from 1 to 6 on it. The user is asked to select a score from the radio button for all 12 questions and then at the bottom the form gives an average score. This all works great but the score doesn't round up to the nearest whole number so it's not as accurate as I would like it to be. Could anyone give me any pointers as to ways of fixing this issue? I have no experience on coding and this is the first time I've used ES2 so go easy with me, the formula I've used just adds up the scores from each of the radio button fields and then divides by 12 (that's the number of questions).
The current code I'm using:
this.rawValue = parseInt(RBQ1.rawValue) + parseInt(RBQ2.rawValue) + parseInt(RBQ3.rawValue) + parseInt(RBQ4.rawValue) + parseInt(RBQ5.rawValue) + parseInt(RBQ6.rawValue) + parseInt(RBQ7.rawValue) + parseInt(RBQ8.rawValue) + parseInt(RBQ9.rawValue) + parseInt(RBQ10.rawValue) + parseInt(RBQ11.rawValue) + parseInt(RBQ12.rawValue) /12;
Solved! Go to Solution.
Views
Replies
Total Likes
I am very sorry for not seeing this at the beginning... when thinking programmatically we tend to forget about the priority of the operators...
You need to have parentheses grouping all the additions together and then dividing it by 12...
Views
Replies
Total Likes
Hi there,
all you have to do is add the method to round up the final value.
To access the round method, you need to use the class Math...
try it this way:
Hope this will help!
Views
Replies
Total Likes
Hi Magus,
Thanks for your reply. I've just tried that but it's the same as it was before. I have to click on 9no 2's before it changes the average score from 1 to 2. I would expect the average score to change from 1 to 2 on the 7th questions as at that point there are 7 questions with a score of 2 and only 5 questions with a score of one.
Regards
Views
Replies
Total Likes
Hi again,
I am not sure why it behaves like this, but make sure the null value of your radio button lists is 0 and not null...
If any value is null in the calculation, it will cause errors in the calculation
E.g.: Have a hidden choice for each radio button lists with 0 as a value.
Hope this will help
Views
Replies
Total Likes
I've customised each radio button to have a value of 1-6. I've gone through the menu's and cannot see anything that says 'null value' anywhere. The default value on them all is 1 unless the user selects another value. A screen shot of the form is below if that helps at all.
Regards
Views
Replies
Total Likes
Hi again,
I've noticed that RBQ1 is not in a subform but any other lists are in a subform...
In your code you are trying to access all the lists the same way, but you can't access directly the lists that are in a subform...
You might want to consider removing the subforms and it should work, or..
name each of the subforms and change your reference_syntax in your code to access the right items.
Views
Replies
Total Likes
I've just changed the forumla to quickly include only 3 of the radio button values and have divided by 3 instead of the usual 12. I've then take the radio forms out of the sub-form to match the RBQ1 setup. This does something different but it's even more random in the way it rounds up. I've selected 1 for all 3 questions and the average is down as 2. I think select 1 and 1 and 6 and it comes back with an average score of 7.
Views
Replies
Total Likes
I've just taken all the radio buttons out of the sub forms and the formula just works as it did without the round up function added. Any ideas?
Views
Replies
Total Likes
I am very sorry for not seeing this at the beginning... when thinking programmatically we tend to forget about the priority of the operators...
You need to have parentheses grouping all the additions together and then dividing it by 12...
Views
Replies
Total Likes
We have a WINNER!! Thanks very much. That works as expected, the only slight problem it may cause is for example: If I select 8no 3's, 1no 2's and 3no 1's. The calculation has added them all up to get 29 then divided by 12 to get 2.4 and so doesn't round up. However when you look at the sheet there are more three's than any other score so having the average score as 2 appears to be wrong, even though the calculation is correct. I'm not sure how the user wants it to appear so this may be fine but how would I go about changing the formula if we wanted to show the most selected answer instead of the average? For example; if no 3 was selected say 5 times compared to the other selections being less than 5 times, how we would show the score to be 3?
Thanks so much for your help!
Views
Replies
Total Likes
Well I am not sure if you'd want to check how many of each you have... you'd have to check separately how many 1pts, 2pts, 3pts and so on to verify which one repeats the most...
But if what you want is really a round UP, you can use the Math.ceil(), instead of round.
I don't know if this will do what you want... otherwise you'd have to check each value of the 6 points to see which one is mostly repeated in the choices
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies