Deprecated: Assigning the return value of new by reference is deprecated in /home/tryangle/public_html/blog/wp-includes/cache.php on line 36

Deprecated: Assigning the return value of new by reference is deprecated in /home/tryangle/public_html/blog/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/tryangle/public_html/blog/wp-includes/theme.php on line 507

Deprecated: Assigning the return value of new by reference is deprecated in /home/tryangle/public_html/blog/wp-content/plugins/codesnippet/codesnippet.php on line 248
Tryangled Dev » 2007 » October » 18

Archive for October 18th, 2007

How to retain the value of check boxes using array ?

Thursday, October 18th, 2007

If we have 4 or more check boxes . then it is little difficult to maintain different names for checkboxes.

the best way is to use array as name of checkbox.  (in_array function)
Example :
<input name=”n1[]” value=”Art” type=”checkbox” <? if (in_array(”Art”,$_POST[n1])) echo “checked”; ?>> Art<br>
<input name=”n1[]” value=”Fashion” type=”checkbox” <? if (in_array(”Fashion”,$_POST[n1])) echo “checked”; ?>> Fashion<br>
<input name=”n1[]” value=”Film” type=”checkbox” <? if (in_array(”Film”,$_POST[n1])) echo “checked”; ?>> Film<br>
<input name=”n1[]” value=”Music” type=”checkbox” <? if (in_array(”Music”,$_POST[n1])) echo “checked”; ?>> Music<br>

so when you post now the checks will be retained.

Posted by Suresh B