0

I want to update all dropdowns by clicking on checkbox. I'm using foreach to get all the selected checkboxes.

This will update all on the page but I want to accomplish this using the class name not the field name

$('select[name=order_status] option[value=1]').attr('selected', 'selected');

I want something like this ".shipping_'+do_csv+'

$('.option_completed').click(function() {
    var do_csv = [];
    $("input[name='options[]']:checked").each(function() {
        do_csv.push($(this).val());
        $(".shipping_'+do_csv+' option[value=1]").attr('selected', 'selected');
    });
});
2
  • What are the classnames for your dropdowns? Commented Oct 31, 2012 at 16:32
  • .shipping_'+do_csv+' gets it value from the checkbox the class could be .shipping_1 or .shipping_3432 depending on the order id Commented Oct 31, 2012 at 16:34

2 Answers 2

1

replace this:

$(".shipping_'+do_csv+' option[value=1]").attr('selected', 'selected');

with that:

$(".shipping_"+$(this).val()+" option[value=1]").attr('selected', 'selected');
Sign up to request clarification or add additional context in comments.

Comments

1

If your class names are shipping_somethinghere and dp_csv is an array of somethinghere's, then I think this is what you're looking for:

$.each(do_csv, function(i, val) {
    $(".shipping_" + val + " option[value=1]").attr('selected', 'selected');
}

Comments

Your Answer

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.