Jump to content

calculating a score


elexion
 Share

Recommended Posts

hey guys, I've been working on a small script that calculates a score based on radio boxes

 function calculate_score(questions, score){ //the current score of the user is 0var current_score = 0;//the maximal score is fivevar score_default = 5;//in order to get the maximal value for each question(s) asked we're going to multiply the max score by the amount of questions //as defined in the second parametervar max_score_per_question = 5 * questions;//we want to calculate how much a user gains per decision he makes var score_per_segment = parseFloat(score_default / max_score_per_question);//-- -- -- -- -- --var score_something = parseFloat(score_per_segment * score); current_score += parseFloat(score_something);document.getElementById("total_score[i]").innerHTML=""+current_score;}

I know the calculations are accurate the only problem is it doesn't add up when there are several questions

 echo "<td>1<input type='radio' name='vraag[]' value=1 onclick='calculate_score(".$aantal.",this.value)'/></td><td>2<input type='radio' name='vraag[]' value=2 onclick='calculate_score(".$aantal.",this.value)'/></td><td>3<input type='radio' name='vraag[]' value=3 onclick='calculate_score(".$aantal.",this.value)'/></td><td>4<input type='radio' name='vraag[]' value=4 onclick='calculate_score(".$aantal.",this.value)'/></td><td>5<input type='radio' name='vraag[]' value=5 onclick='calculate_score(".$aantal.",this.value)'/></td></table></form>";

given the HTML I wonder if it's because everytime I click a radio box the value is set to 0 again....any tips?

Link to comment
Share on other sites

placevar current_score = 0; outside the function so it resets only when page loaded
how do I add this score for each record out of a database?record1[unique score]record 2[unique score]
Link to comment
Share on other sites

I don't know what each [unique score] relates to? in you first example. all i know is that in your script that you don't seriously have a id ref of "total_score"??? I seriously don't think so.
if I made an element that contains an array and append it to every record my script produces would this be achievable?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...