Get multiple values ​​checkbox tag

22 views
Skip to first unread message

Alessandra Padovam

unread,
Oct 7, 2014, 9:25:52 AM10/7/14
to rubyonra...@googlegroups.com
Hello everybody!

I am displaying a table with data coming from an xml so I'm stepping
through the array and assembling the elements of each row. Each line has
a check_box_tag to select the elements you wish to delete.
Now what I need is to extract each selected two elements, that would be
the identification code and date. Because for delete I need to request
data with these two. The problem is that I am unable to extract two
columns by clicking on check_box_tag. I have a javascript function to
store the selected elements in an array I would also have to change this
function to store in a multidimensional array. My main doubt now is how
to extract these two columns by clicking on check_box_tag. Could someone
help me please?

Loop to display the contents coming 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 funtion:

// Insere na textbox especificada em fieldname os ids selecionados na
listagem através dos checkbox
//(criado para ser utilizado a exportação/impressão do relatório
consolidado)
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!

:) Ale

--
Posted via http://www.ruby-forum.com/.

Hassan Schroeder

unread,
Oct 7, 2014, 2:05:34 PM10/7/14
to rubyonrails-talk
On Tue, Oct 7, 2014 at 6:24 AM, Alessandra Padovam <li...@ruby-forum.com> wrote:

> I am displaying a table with data coming from an xml so I'm stepping
> through the array and assembling the elements of each row. Each line has
> a check_box_tag to select the elements you wish to delete.
> Now what I need is to extract each selected two elements, that would be
> the identification code and date.

> My main doubt now is how to extract these two columns by clicking
> on check_box_tag.

Maybe I'm misunderstanding your use case, but why not just make
the checkbox tag value = the data values you need to start with?

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

Alessandra Padovam

unread,
Oct 7, 2014, 2:46:50 PM10/7/14
to rubyonra...@googlegroups.com
I am accessing an external webservice to display and manipulate data.
The table is displayed in the view based on reading an external xml,
array values ​​are dynamic.
My goal is to select the checkbox two attributes get this array as
parameters that will be needed to delete the record in the webservice.
Everything would be easier if the webservice make available a single
key, but it is not possible.

So now I'm trying to create a unique id at runtime for each checkbox
selected in the elements and try to get it online.

Hassan Schroeder

unread,
Oct 7, 2014, 2:52:08 PM10/7/14
to rubyonrails-talk
On Tue, Oct 7, 2014 at 11:45 AM, Alessandra Padovam
<li...@ruby-forum.com> wrote:
> I am accessing an external webservice to display and manipulate data.
> The table is displayed in the view based on reading an external xml,
> array values are dynamic.
> My goal is to select the checkbox two attributes get this array as
> parameters that will be needed to delete the record in the webservice.
> Everything would be easier if the webservice make available a single
> key, but it is not possible.

?? So merge what you need into "value1_value2" or whatever and
parse it back into 2 values on the server.
Reply all
Reply to author
Forward
0 new messages