Re: QuickForm hierselect muiltiple choice problem
| From: | Joshua Eichorn | Date: | Thu, 03 Jun 2004 16:55:14 +0000 |
| Subject: | Re: QuickForm hierselect muiltiple choice problem | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-12877@lists.php.net to get a copy of this message | ||
Joshua Eichorn wrote:
You should be able to get it working for the attached fileI don't think an attachment makes it to the list, here is the code inline: <?php require_once 'HTML/QuickForm.php';
$form = new HTML_QuickForm();
$opt_main = array(
1 => 'Arizona',
2 => 'California',
3 => 'Nevada'
);
$opt_sec[1] = array('Phoenix','Tuscon','Ajo'); $opt_sec[2] = array('Los Angeles','San Francisco'); $opt_sec[3] = array('Los Vegas');
$opts = array($opt_main,$opt_sec);
/* setup custom hier select js method */
if (!defined('HTML_QUICKFORM_HIERSELECT_EXISTS'))
{
$_js = "function swapOptions(frm, grpName, eleIndex, nbElements, arName)\n"
."{\n"
." var n = \"\";\n"
." var ctl;\n\n"
." for (var i = 0; i < nbElements; i++) {\n"
." ctl = frm.form[grpName+'['+i+']'];\n"
." if (ctl == null) {\n"
." ctl = frm.form[grpName+'['+i+'][]'];\n"
." }\n"
." if (i <= eleIndex) {\n"
." n += \"_\"+ctl.value;\n"
." } else {\n"
." ctl.length = 0;\n"
." }\n"
." }\n\n"
." var t = eval(\"typeof(\"+arName + n +\")\");\n"
." if (t != 'undefined') {\n"
." var the_array = eval(arName+n);\n"
." var j = 0;\n"
." n = eleIndex + 1;\n"
." ctl = frm.form[grpName+'['+ n +'][]'];\n"
." for (var i in the_array) {\n"
." opt = new Option(the_array[i], i, false, false);\n"
." ctl.options[j++] = opt;\n"
." }\n"
." }\n"
."}\n\n";
define('HTML_QUICKFORM_HIERSELECT_EXISTS', true);
}
$multi =& $form->addElement('hierselect', 'cities', 'Cities:',array('size'=>3),' ');
$multi->setOptions($opts);
$multi->_js .= $_js;
$els =& $multi->getElements(); $els[1]->updateAttributes(array('multiple','multiple'));
$form->display();
?>
-josh