Re: multiselects and arrays

From: Date: Thu, 10 May 2001 16:58:32 +0000
Subject: Re: multiselects and arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-52322@lists.php.net to get a copy of this message
You can use javascript with this naming convention, just not the way you're probably doing it. Here's a working example: <html> <head> <title></title> </head> <body> <script language="javascript" type="text/javascript"> function getValue(field) { var form = document.testform; var temp = form[field].value; return(temp); } function getArrayValue(field, index) { var form = document.testform; var temp = new Array(); var type = form.type; for (i=0; i<form.length; i++) { if (form[i].name == field) { temp.push(form[i].value); } } if (temp.length >= index) { return(temp[index]); } else { return(false); } } function test() { test_0 = getValue("test[0]"); test_1 = getValue("test[1]"); test_2 = getValue("test[2]"); test2_0 = getArrayValue("test2[]", 0); test2_1 = getArrayValue("test2[]", 1); alert( "test_0 = " + test_0 + "\n" + "test_1 = " + test_1 + "\n" + "test_2 = " + test_2 + "\n" + "test2_0 = " + test2_0 + "\n" + "test2_1 = " + test2_1 + "\n" ); } </script> <form name="testform"> <table> <tr> <td>test[0]</td> <td><input type="text" name="test[0]" value="this is test 0"></td> </tr> <tr> <td>test[1]</td> <td><input type="text" name="test[1]" value="this is test 1"></td> </tr> <tr> <td>test[2]</td> <td><input type="text" name="test[2]" value="this is test 2"></td> </tr> <tr> <td>test2[]</td> <td><input type="text" name="test2[]" value="this is test2 0"></td> </tr> <tr> <td>test2[]</td> <td><input type="text" name="test2[]" value="this is test2 1"></td> </tr> <tr> <td colspan="2"><input type="button" value="test" onclick="javascript:test();"></td> </tr> </table> </form> </body> </html> Hope this helps. --Toby ----- Original Message ----- From: "Max Vysotskiy" <Maxim_Vysotskiy@ep.minsk.by> To: <php-general@lists.php.net> Sent: Thursday, May 10, 2001 11:06 AM Subject: [PHP] multiselects and arrays > Hi. > Why doesn't PHP convert mutiselect values with plain names (not array-like) > to arrays. Is there any reason to not doing this? > > Example: > I have a page with multiselect, which name is SEL1 > (I cannot use square brackets because I need to use a JavaScript on the > page, so, it's not allowed in variable names to contain [ ] ). When browser > submits this page, and if there are sew values selected in this multiselect, > it just sends this values along to each other with same name. > (such as in case of GET method: http://somehost.com/index.php?SEL1=1&SEL2=2) > So, why not parse this, and in case if there are more than one variable with > same name, convert this variable to array, and put all the values there? > Thanx > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#52322) next »