开发者

problems with check_box_tag in rails

this is a very odd issue. i have checkbox tags in a form, that look as such:

=check_box_tag 'ids[]', img.id, false, {:name=>'checkbox'}

i 开发者_JAVA百科am enumerating them (as done in this railscast http://media.railscasts.com/videos/052_update_through_checkboxes.mov) in order to get a param back called "ids" which is an array of all the ids corresponding with checked boxes.

this works well when I use:

 =check_box_tag 'ids[]', img.id

however, I need to set the name as well because I want to have a "select-all" check box available... but as soon as I add those last two parameters, the param ids no longer works! it no longer gets passed.

any idea why or what I could do?

thank you.


since i had to get around using the name param for the checkbox, i did this sneaky javascript. hope it helps someone.

send in

checkAll(document.name_of_form);

the js: (note that check_all is the name of the main checkbox which is selected when one wants to check all. this was the only named check box)

function checkAll(form){
if(form.check_all.checked == true)
    select_all = true;
else
    select_all = false;

form_elems = form.getElementsByTagName("input");
for(k=0; k < form_elems.length; k++){
    if(form_elems[k].type == 'checkbox')
        form_elems[k].checked = select_all;
}

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜