Hi Terence Assign ids to multiple select field and then use id attribute of select tag in JavaScript to access (copy,del etc.) instead of using the name attribute.
Hope this helps. Cheers Binay ----- Original Message ----- From: "Terence" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, December 29, 2003 11:46 AM Subject: [PHP] multiple select option alternative to field_name[] > Dear All, > > The only way I know to retrieve all the values from a multiple select field > is to use > the square brackets after the field name ie. user_id[] > > The problem however is that when I use a javascript function to transfer the > items > from multiple_select_list1 to multiple_select_list2, I cannot use the square > brackets > in a field name, as this obviously conflicts with something in the script. > > So I am wondering if there's any other way in PHP to get the items, or do I > have > to find an alternative way in javascript? If anyone has ideas it would be > great. > > Thanks > Terence > > > > my code: > > (This works) > > echo "<select name='select1' multiple size='7' > class='inputstyle'>....</select>\n"; > > <input type='button' class='buttonstyle' value=' > ' onClick=\"if > (document.images) copySelected(this.form.select1,this.form.select2)\"> > <input type='button' class='buttonstyle' value=' < ' onClick=\"if > (document.images) copySelected(this.form.select2,this.form.select1)\"> > <input type='button' class='buttonstyle' value='>>' onClick=\"if > (document.images) copyAll(this.form.select1,this.form.select2)\"> > <input type='button' class='buttonstyle' value='<<' onClick=\"if > (document.images) copyAll(this.form.select2,this.form.select1)\"> > > <select name='select2' multiple size='7' class='inputstyle'>....</select> > > (This is the problem - notice the square brackets behind select2) > > echo "<select name='select1' multiple size='7' > class='inputstyle'>....</select>\n"; > > <input type='button' class='buttonstyle' value=' > ' onClick=\"if > (document.images) copySelected(this.form.select1,this.form.select2[])\"> > <input type='button' class='buttonstyle' value=' < ' onClick=\"if > (document.images) copySelected(this.form.select2[],this.form.select1)\"> > <input type='button' class='buttonstyle' value='>>' onClick=\"if > (document.images) copyAll(this.form.select1,this.form.select2[])\"> > <input type='button' class='buttonstyle' value='<<' onClick=\"if > (document.images) copyAll(this.form.select2[],this.form.select1)\"> > > <select name='select2[]' multiple size='7' class='inputstyle'>....</select> > > > Javascript: > > echo "<script language='JavaScript'><!--\n"; > echo "function deleteOption(object,index) {\n"; > echo "object.options[index] = null;\n"; > echo "}\n"; > > echo "function addOption(object,text,value) {\n"; > echo "var defaultSelected = true;\n"; > echo "var selected = true;\n"; > echo "var optionName = new Option(text, value, defaultSelected, > selected)\n"; > echo "object.options[object.length] = optionName;\n"; > echo "}\n"; > > echo "function copySelected(fromObject,toObject) {\n"; > echo "for (var i=0, l=fromObject.options.length;i<l;i++) {\n"; > echo "if (fromObject.options[i].selected)\n"; > echo > "addOption(toObject,fromObject.options[i].text,fromObject.options[i].value); > \n"; > echo "}\n"; > echo "for (var i=fromObject.options.length-1;i>-1;i--) {\n"; > echo "if (fromObject.options[i].selected)\n"; > echo "deleteOption(fromObject,i);\n"; > echo "}\n"; > echo "}\n"; > > echo "function copyAll(fromObject,toObject) {\n"; > echo "for (var i=0, l=fromObject.options.length;i<l;i++) {\n"; > echo > "addOption(toObject,fromObject.options[i].text,fromObject.options[i].value); > \n"; > echo "}\n"; > echo "for (var i=fromObject.options.length-1;i>-1;i--) {\n"; > echo "deleteOption(fromObject,i);\n"; > echo "}\n"; > echo "}\n"; > echo "//--></script>\n"; > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php