working with checkboxes - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: working with checkboxes (/showthread.php?tid=37848) |
working with checkboxes - El Forum - 01-22-2011 [eluser]black.Blank[/eluser] I have let say for example 5 checkboxes for group 1 and 4 checkboxes for group 2. Now, I have to check if the user has selected at least one option for each group. When the user clicks the submit button and no option has been selected for groups 1 and 2, then an error message will be displayed (i guess an alert message--javascript..) Thanks in advance working with checkboxes - El Forum - 01-23-2011 [eluser]Petsoukos[/eluser] You will create your form the usual way. Create the checkboxes and setup their name attributes as array. e.g. 'name' => 'group1[ ]', See the example bellow. Code: echo form_open('the_link_to_your_controller'); Then in your controller grab those posted values and make a simple IF statement: Code: function process() { This will guarantee that your user checked at least 1 checkbox on each group. This is how I would do it and I've tested it and it works. I suggest you wait for other responses also. Maybe there is another more efficient way to do the same thing. working with checkboxes - El Forum - 01-23-2011 [eluser]black.Blank[/eluser] thanks will try if it works working with checkboxes - El Forum - 01-23-2011 [eluser]black.Blank[/eluser] is there any other way how can i enable/disable radio buttons and checkboxes besides this.. for example.. Code: if(document.forms[0].elements["sample"].checked) { working with checkboxes - El Forum - 01-23-2011 [eluser]Petsoukos[/eluser] [quote author="black.Blank" date="1295814795"]is there any other way how can i enable/disable radio buttons and checkboxes besides this.. for example.. Code: if(document.forms[0].elements["sample"].checked) { Enable/Disable via? Buttons? Mass select checkboxes? Sorry but I didn't get the question. |