List the number of selected values in a dropdown

louis037

Member
Hello, I want to count the number of selected values in a dropdown in order to show it in a field.

My jquery code to get the number of options works fine :
JavaScript:
var selectTrainees = $('data_trainings___trainings_trainnes').length;
var numberTrainees = $('data_trainings___training_total_trainees');
if (selectTrainees !== '') {
numberTrainees.value = selectTrainees;
}

Could you help me, it shoud be very tricky... Thanks
 
If you are doing this in a JS 'change' (or 'click') event on the element with the options you want to count, this would do it ...

Code:
this.form.formElement.get('data_trainings___training_total_trainees').update(this.getValue().length);

-- hugh
 
I tested it like that :
Code:
var selectTrainees = $('data_trainings___trainings_trainees').getValue();
var number = $('data_trainings___trainings_trainees').getValue().length;
var numberTrainees = $('data_trainings___training_total_trainees');
if (selectTrainees !== '') {
numberTrainees.value = number;
}
This doesn't work, the console says : SyntaxError: missing ) after condition
 
Why not use a calc element?
Try this code as the Calculation...
PHP:
$trainees = '{data_trainings___trainings_trainees_raw}';
return count(explode(',',$trainees));
 
Thank you Bauer,
I don't use calc element because when I activate it, the form doesn't load, even if I write
Code:
return '1';
in it. I don't know why???? I use the last fabrik release.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top