I have programmed an online assessment which can calculate the total score and display it as a percentage. However, each of the questions pertain to different categories and I would like to be able to calculate and show the results for the different categories.
Example: I need to sum radio buttons 1, 9, 17, 25 & 33 for the “career” category and display the result in the “career” category text field in the results box at the bottom of the page. I have 8 categories and don’t want to put all the questions for each category together because the person taking the assessment will figure out how it’s calculated and might manipulate it to get a higher score. I have googled so many alternatives and they only show adding(sum) radio buttons consecutively. Please can someone help me with the code for this as I have no clue and have spent 2 days trying to figure it out.
In the name property of the radio button, you must add the category name. (eg. radiogroup23career)
Then make a hidden input field in your page for each category.
Have a logic in your javascript to add up each button by category(a part of the name field). $(‘input[name*=”career”]’).val(); (JQuery to search for an element by a part of the name)
Then set the hidden input field with that value.
Then do a form post, preserving the current results in the hidden fields.
Do the same on page 2 just make sure to add the results to the results posted from the previous page.
Hope this helps,
pH
See more details below:
And in your JQuery do as follows
Loop through all your:
$(‘input[name*=”career”]’).val() items.
and add them up to a var named “careertotal”
set that value to your hidden field.