Page 1 of 1

Looking for help with check boxes

Posted: Tue Jun 17, 2014 8:13 pm
by andyk

First off my apologies, my JavaScript skills are minimal.

I have a simple app which has a set of questions on the page that the user answers and each answer has a numerical value. I have a JavaScript that fires when a button is clicked and their total score is then displayed on the same screen.

One question has changed and now consists of 3 options which I have set up as checkboxes. The user can select one, two or all of the options and each option has a different value (1,5, 2). I have set the value of each checkbox in the Properties.

I want to use JavaScript to take the total of all three checkboxes and add them into my final total, but whatever I try returns NaN as the total. This is all set up on one page, so I don't think I need any stored variables.

I think this should be pretty simple, but I am having more problems with it than I should. Any help is appreciated.


Looking for help with check boxes

Posted: Tue Jun 17, 2014 9:02 pm
by Kateryna Grynko

Hi,

Could you please post the code you use?


Looking for help with check boxes

Posted: Tue Jun 17, 2014 9:17 pm
by andyk

Just for the checkbox portion? I am almost embarrassed to as I am sure it is laughably wrong!

There are three questions

  1. Sleep debt: depending on the amount entered the factor is 1,3, or 5

  2. Wakefulness: Depending on the amount of hours entered the scoring factor is again 1,3, or 5

  3. The checkboxes (var wocl): Three options No, and two Yes options that cover different times of day. Scores for each are 1, 5, and 2
    The amounts are then totaled and a panel opened depending on the total

    The JS works for the first two questions and the panels open as expected.

    This is what I have for the CheckBoxes:

    var wocl = Number(Apperyio("wocl1_No" + "wocl2_Yes" + "wocl3_Yes").val());

    var RiskAmount = finaldebt+wake+wocl;


Looking for help with check boxes

Posted: Wed Jun 18, 2014 4:11 pm
by andyk

I've answered my own question. I was treating each of the text box element separately instead of the checkbox a complete container.


Looking for help with check boxes

Posted: Wed Jun 18, 2014 4:33 pm
by Kateryna Grynko

Hi,

This code is incorrect:preApperyio("wocl1_No" + "wocl2_Yes" + "wocl3_Yes").val()/preAs you need to sum only checked values you could use the following code:prevar mobilecheckboxgroupTotalSumm = 0;
Appery("mobilecheckboxgroup").find(":checked").each(function(){
mobilecheckboxgroupTotalSumm += parseInt($(this).val());
}); /preWhere mobilecheckboxgroupName is a name of chechbox group.


Looking for help with check boxes

Posted: Wed Jun 18, 2014 4:34 pm
by andyk

Thank You!


Looking for help with check boxes

Posted: Sat Aug 15, 2015 4:50 pm
by umama fakher

Thank you soooo Much ^_^ :))) !!!