Monday, March 12, 2012

jquery function for changing values of text boxes and dropdowns in rows if the checkbox of the row is checked

Sample jquery function for applying values to text box, select drop down for the selected checkboxes rows.

I have some rows with checkbox first, then a input field and a dropdown. I need to change the value of dropdowns and text boxes whose checkboxes are checked when click on a button. As there is no direct relationship between the checkbox, textbox and drop down, at first it seems to be difficult.

But in jquery it is so simple.

function btn_apply_all(){

        $("input[name='product_checkbox[]']").each(function(key) {
            if(this.checked){
                $("select[name='option_price[]']").each( function (key1){   
                    if(key1==key){   
                        $(this).val($("#cbo_bulk").val());   
                    }
                });
       
                $("input[name='txt_opt_price[]']").each( function (key1){
                    if(key1==key){   
                        $(this).val($("#txt_bulk_price").val());   
                    }
                });
       
            }
           
        });

    }

No comments:

Post a Comment