andyk
Posts: 0
Joined: Mon Jun 02, 2014 5:44 pm

Looking for help with check boxes

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.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Looking for help with check boxes

Hi,

Could you please post the code you use?

andyk
Posts: 0
Joined: Mon Jun 02, 2014 5:44 pm

Looking for help with check boxes

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;

andyk
Posts: 0
Joined: Mon Jun 02, 2014 5:44 pm

Looking for help with check boxes

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Looking for help with check boxes

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.

andyk
Posts: 0
Joined: Mon Jun 02, 2014 5:44 pm

Looking for help with check boxes

Thank You!

umama fakher
Posts: 0
Joined: Fri May 22, 2015 4:26 pm

Looking for help with check boxes

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

Return to “Issues”