note 23174 added to language.variables.predefined

From: Date: Thu, 11 Jul 2002 03:24:44 +0000
Subject: note 23174 added to language.variables.predefined
Groups: php.notes 
Request: Send a blank email to php-notes+get-32877@lists.php.net to get a copy of this message
Like others, I was struggling with getting arrays of checkboxes into a PHP array. The notes here have helped, but simply changing the name (vimal@uta.edu 29-Apr-2002) to 'something[]' produces syntax errors when trying do something (anything!) useful with the controls in JavaScript - for example, using a JS function to select or de-select each control in the array - so I came up with this... Have pairs of controls: <INPUT TYPE="checkbox" NAME="CB"> <INPUT TYPE="hidden" NAME "CB_VALUE" VALUE="whatever"> Replace the submit button with: <INPUT TYPE="button" onClick="doSubmit();"> This JS function changes the checkbox name from CB_VALUE to CB_VALUE[], submits the form and presents PHP with CB_VALUE[0] to CB_VALUE[n]. function doSubmit() { for (i=1;i<document.forms[0].CB.length;i++) { document.forms[0].CB_VALUE[i].name='CB_VALUE[]'; } document.forms[0].submit(); } To only present checked items in the resulting PHP array amend the function to: if (document.forms[0].CB[i].checked==true) { document.forms[0].CB_VALUE[i].name='CB_VALUE[]'; } Much to my surprise it actually works. Andrew (PHP novice). -- http://www.php.net/manual/en/language.variables.predefined.php http://master.php.net/manage/user-notes.php?action=edit+23174 http://master.php.net/manage/user-notes.php?action=delete+23174 http://master.php.net/manage/user-notes.php?action=reject+23174

« previous php.notes (#32877) next »