I'm displaying a table with data coming from a xml
, so I'm traversing the array @ag
and assembling the elements of each line. Each line has a check_box_tag
to select the elements to delete.
Now what I need is each line selected to extract two elements, which would be ID and date code, since deleting I need to give request with these two data. The problem is that I am not able to extract two columns by clicking check_box_tag
.
I have a function in javascript to store the selected elements in an array I would also have to change this function to store in a multidimensional array. My main question now is how to extract these two columns by clicking on check_box_tag
.
Loop to display content from xml
:
<% @ag.each do |x| %>
<tr>
<td align="center">
<%= check_box_tag "#{x[0]}", 0, false, :name=> "chk_del", :onclick => "MultiSelectIDs('chk_del');" %>
</td>
<% x.each do |y| %>
<td align="center"><%= y%></td>
<% end %>
</tr>
<% end %>
<%= text_field_tag :selected_ids, "", :size=>100 %>
javascript function:
// Insere na textbox especificada em fieldname os ids selecionados na listagem através dos checkbox
function MultiSelectIDs(FieldName) {
var selected_ids = new Array()
var objCheckBoxes = document.getElementsByName(FieldName);
for(var i = 0; i < objCheckBoxes.length; i++){
if (objCheckBoxes[i].checked) {
var x = selected_ids.splice(selected_ids.length,0, objCheckBoxes[i].id);
}
}
document.getElementById('selected_ids').value = selected_ids.join(", ")
};
Thank you!