Forums

Calculating the number of radio buttons selected.. and some

abasel 02 May, 2013
[attachment=0]Form.PNG[/attachment]
On clicking "Calculate" I am needing to achieve the following:
1) Calculate how many radio buttons have been selected - I am not sure of how to code this.
2) The calculate button must only work if one or more radio buttons are selected.

[attachment=1]RadioButtons.PNG[/attachment]

I Am using Multi Pages to move to the next section.
Max_admin 10 May, 2013
Hi,

A quick code, not tested though🙂

your radios should have the same class:


var total = 0;
$$('.class_here').each(function(rad){
if(rad.checked == true){
total = total + 1;
}
});
if(total > 0){
//do here what you need!
}


Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
abasel 11 May, 2013
Hi Max, Chronoform generates the following type of code

<div class="ccms_form_element cfdiv_radio" id="narrowlabel_container_div" style="">
  <label for="NarrowLabel">Mon</label>
  <input type="hidden" name="Monday" value="" alt="ghost" />
  <div style="float:left; clear:none;">
    <input type="radio" name="Monday" id="monday_0" title="" value="0" checked="checked" class="" />
    <label for="monday_0">N/A</label>
    <input type="radio" name="Monday" id="monday_1" title="" value="CLA" class="" />
    <label for="monday_1">Cyber A</label>
    <input type="radio" name="Monday" id="monday_2" title="" value="MLA" class="" />
    <label for="monday_2">Minecraft A</label>
  </div>
  <div class="clear"></div>
  <div id="error-message-Monday"></div>
</div>


When I go to configure the radio button via the wizard, I can't see where to set the class. I am probably missing something that is very obvious 😶
GreyHead 11 May, 2013
Hi abasel,

I think that you can probably do it by wrapping a div around the radio block - or in your case, as they are the only radio buttons in the form, use the form class as a selector like this (not tested):
var radios = $$('.Chronoform radio:checked').length;
if ( radios > 2 ) {
   // do something . . .
}

Bob
abasel 12 May, 2013
Thanks for that.. in the end I decided to to calculate it on the second page and then the visitor can simply use the back botton to make changes
This topic is locked and no more replies can be posted.