0

I want to pass a parameter into my function. The parameter will be a variable that representsa CSS class name. Based upon which checkbox was selected I will set the value of the variable (eg, if CheckBox1 was selected the value of the variable would be the class name '.list1').

The dropdownlist has a large number of options and I want to select a subset of the options based on their 'class' and use those options to populate another list (fl_listEmpty).

Here is my code as far as I've gotten:

 function FillDropDownList(parameter) {
 $('.fl_list1 [**put class name parameter here**]).each(function (index) {
 $(".fl_listEmpty").append($('<option> </option>').val(index).html($(this).text()));
 })
 }
asked Sep 22, 2011 at 19:48
1

2 Answers 2

1

Just compose the selector as if it were a string (which it is).

 function FillDropDownList(parameter) {
 $('.fl_list1 ' + parameter).each(function (index) {
 $(".fl_listEmpty").append($('<option> </option>').val(index).html($(this).text()));
 })
 }
answered Sep 22, 2011 at 19:51
Sign up to request clarification or add additional context in comments.

Comments

0

Assuming your space is intentional between classes, a find would be appropriate. If it is possible that the value may be undefined, you could just make a condition:

function FillDropDownList(parameter) {
 var selset = parameter ? $('.fl_list1').find('.' + parameter) : $('.fl_list1');
 selset.each([** your function here **]);
}
answered Sep 22, 2011 at 19:59

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.