In my rails app, a list of record is shown with checkboxes in front of each record and a checkbox to select all the records. I want to add or remove the parents_contact_no data to the text area. On select of checkboxes corresponding record's parents_contact_no should get added to the text area separated by comma and on unselect of the checkbox of corresponding record the corresponding record's parents_contact_no should get removed. If the select all checkbox is selected than parents_contact_no of all record should get added to the text area.
Text area in which numbers has to be dispayed
<div class="field">
<%= f.label :sent_to %><br>
<div class="result_div">
<%= f.text_field :sent_to %>
</div>
</div>
.html.erb file
<% if @contact.empty? %>
<h4>No records to display</h4>
<% else %>
<table>
<thead>
<tr>
<th><%= check_box_tag "contact_nos[]", @contact.map(&:parents_contact_no) %></th>
<th>Roll no</th>
<th>Class</th>
<th>Section</th>
<th>Father name</th>
<th>Parents contact no</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @contact.each do |student| %>
<tr>
<td><%= check_box_tag "contact_no[]", student.parents_contact_no %></td>
<td><%= student.roll_no %></td>
<td><%= student.class_name %></td>
<td><%= student.section %></td>
<td><%= student.father_name %></td>
<td><%= student.parents_contact_no %></td>
<td><%= link_to 'Show', student %></td>
<td><%= link_to 'Edit', edit_student_path(student) %></td>
<td><%= link_to 'Destroy', student, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
How to do this via jquery/javascript?
Aucun commentaire:
Enregistrer un commentaire