read about checkbox in HTML.
Submit multi-select checkbox values
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <script> function select(a) { var theForm = document.myForm; for (i=0; i<theForm.elements.length; i++) { if (theForm.elements[i].name=='mycheckbox[]') theForm.elements[i].checked = a; } } </script> <form name="myForm" method="POST"> <input type="checkbox" name="mycheckbox[]" value="Red">Red<br/> <input type="checkbox" name="mycheckbox[]" value="Blue">Blue<br/> <input type="checkbox" name="mycheckbox[]" value="Green">Green<br/> <input type="submit" value="Submit" name="B1"> </form> <a href="javascript:select(1)">Check all</a> | <a href="javascript:select(0)">Uncheck all</a> |
Using PHP to receive the checkbox values
we can receive the submitted values in second page and complete the processes, but now I will only print out the values I have select from the first page, and I will use a simple PHP code.
1 2 3 | <?php print_r($mycheckbox); ?> |
so the result will be an array of two values.
Array ( [0] => Blue [1] => Green )
first array value [0] => Blue
second array value [1] => Green
I will make some simple process to add some colors to the result in the second file.
1 2 3 4 5 6 7 8 9 | <?php for ($i=0; $i<count($mycheckbox);$i++){ if ($mycheckbox[$i]=="Red") $font="<b><font color='#FF0000'>"; if ($mycheckbox[$i]=="Blue") $font="<b><font color='#0000FF'>"; if ($mycheckbox[$i]=="Green") $font="<b><font color='#008000'>"; echo $font."$mycheckbox[$i]</font></b><br>"; } ?> |
the result will be like this
Red
Green
If this post was good and helpful for you, Please give it Like.
.
0 comments:
Post a Comment