Reputation: 57
For example I have 5 checkboxes and all of them have same name. I check checkboxes, submit and then delete checkboxes I checked. Here I don´t have any problems, the problem it´s check for example the number 1 , 3 , 5 , etc , but has the same name and when check one uncheck other
How it´s possible check all checbox i want from for example 5 checboxes
For example :
Check 1 - checked
Check 2 - unchecked
Check 3 - checked
Check 4 - unchecked
Check 5 - checked
Thank´s Regards
Upvotes: 0
Views: 5092
Reputation: 418
If you want to delete checkbox you check then this could help if you use jQuery
1 <input type='checkbox' name='my_name' /><br>
2 <input type='checkbox' name='my_name' /><br>
3 <input type='checkbox' name='my_name' /><br>
4 <input type='checkbox' name='my_name' /><br>
5 <input type='checkbox' name='my_name' /><br>
<script type="text/javascript">
// Event handler activates when value of input with specified name is changed
$("input[name=my_name]").on("change", function(event) {
// checks if checkbox was checked, if so - deletes it
if (true === $(this).prop('checked')) $(this).remove();
});
</script>
Upvotes: 0
Reputation: 16595
use id's to identify them individually:
<input type='checkbox' name='name' id='cb_1'/>
<input type='checkbox' name='name' id='cb_2'/>
<input type='checkbox' name='name' id='cb_3'/>
<input type='checkbox' name='name' id='cb_4'/>
<input type='checkbox' name='name' id='cb_5'/>
Upvotes: 2
Reputation: 382102
If you really can't give them different names or id and you want to check them all :
$('input[name="thename"]').prop('checked', true);
If you want to check the first, the third and the fifth checkbox, you can do this :
$('input[name="thename"]').filter(':eq(0), :eq(2), :eq(4)').prop('checked', true);
Upvotes: 4