Count the number of boxes checked in a database join?

porlhews

Member
Hi Everyone,

I have a databasejoin which renders as a multicheck box. I'm trying to figure out a way of counting the number of boxes checked so I can validate it (i.e. I want to ensure a minimum number of boxes are checked).

I figured out how to do it with a regular checkbox element, but I'm struggling with a databasejoin......

Thanks in advance,

Paul Hughes

Joomla! 2.5.16
php 5.4.21
fabrikar 3.0.9.1
Community Builder 1.9.1
 
Hello again,

OK, I've been working on this for the last few evenings, but I finally cracked it. So for anyone else who might be interested.

I figured that I wasn't strictly interested in counting the number of boxes that are checked, but rather being able to compare the number that are checked to another number (which is entered into a field elsewhere in my form).

I have my databasejoin which is rendered as a multi-checkbox.
On the databasejoin element, I added the following javascript to set the value of a third element as being yes or no. I validated this third element with a php validation.

I'm pretty certain that using the numChecked variable, the number of boxes could be checked and this could be loaded into a field, but I didn't need to in the end.

Hope it helps somebody.

Cheerio,

Paul Hughes



Code:
var numChecked = this._getSubElements().filter(function (c) {return c.value !== '0' ? c.checked : false}).length;
 
var required = form_2.formElements.get('jos_tablename___element_number').getValue();
 
if (numChecked >= required ) {
  Fabrik.blocks['form_2'].formElements.get('jos_tablename___element_yes_or_no').update('Yes') ;
}
else{
Fabrik.blocks['form_2'].formElements.get('jos_tablename___element_yes_or_no').update('No') ;
}
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top