最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Select multiple checkbox with same name - Stack Overflow

programmeradmin2浏览0评论

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

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

Share edited Sep 13, 2012 at 11:46 Minimihi 4172 silver badges11 bronze badges asked Sep 13, 2012 at 10:58 FranFran 571 silver badge10 bronze badges 2
  • 1 Set up a fiddle for this. Ans post what you've tried. – Vinayak Phal Commented Sep 13, 2012 at 11:01
  • and i want - for delete i check - send and delete the checkboxes i check , for this i haven´t problem Can you elaborate? please. – Ram Commented Sep 13, 2012 at 11:05
Add a ment  | 

3 Answers 3

Reset to default 4

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);

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'/>

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>

http://jsfiddle/56nBw/1/

发布评论

评论列表(0)

  1. 暂无评论