jwhite68 Posted April 13, 2007 Share Posted April 13, 2007 I have an issue with multiple select lists, javascript and PHP. I have two multiple select lists, list1 and list2. The idea is that items in list1 can be moved individually from list1 to list2. At the end, I want to pass the values from list2, as an array, back to be processed within PHP. The problem currently is that with name="list2", I dont think PHP is seeing it as an array, and I need it to be name="list2[]", but then when I change it to this, I get a javascript error at runtime - so javascript doesnt like the []. Can anyone advise a way around this? See PHP code section below - which you can see generates the javascript via echo commands. <? if ($type=="single") { echo ' <div class="d841"><strong> 05. Country to display product in</strong>'.$errs[1].'<a name="err1"></a></div> <div class="t841" id="title"> <table border="0" cellspacing="0" class="formcontent"> <tr> <td class="td135" style="text-align:right !important"><span'.$hlight1.'>Country</span></td> <td colspan="5" class="td675"> <select name="country" style="width:385px"> <option value="">Select country</option>'; foreach ($countries as $key => $value) { echo '<option value="'.$key.'">'.$value.'</option>'; } echo '</select> </td> </tr> </table> </div>'; } else { echo ' <div class="d841"><strong> 05. Countries to display product in</strong></div> <div class="t841" id="title"> <table border="0" cellspacing="0" class="formcontent"> <tr> <td class="td135" style="text-align:right !important"><span>Country</span></td> <td colspan="5" class="td675"> <select multiple size="10" name="list1" style="width:150">'; foreach ($countries as $key => $value) { echo '<option value="'.$key.'">'.$value.'</option>'; } echo '</select> <input type="button" onClick="move(this.form.list2,this.form.list1)" value="<<" style="width:30px" /> <input type="button" onClick="move(this.form.list1,this.form.list2)" value=">>" style="width:30px" /> <select multiple size="10" name="list2" style="width:150"></select> </td> </tr> </table> </div>'; } ?> Link to comment https://forums.phpfreaks.com/topic/46828-multiple-select-list-issue-with-php-and-javascript/ Share on other sites More sharing options...
Barand Posted April 13, 2007 Share Posted April 13, 2007 Keep the names as "list1[]" (for PHP posting) but address them via their id in the js script eg <html> <head> <meta name="generator" content="PhpED Version 4.5 (Build 4513)"> <title>sample</title> <meta name="author" content="Barand"> <link rel="shortcut icon" href=""> <script language='javascript'> function click1(id) { var $obj = document.getElementById(id); alert ($obj.name + " : Value " + $obj.value); } </script> </head> <body> <form name='fm1' method='get'> <select name='list1[]' id='list1' size='3' onclick='click1(this.id)'> <option value='A'>A</option> <option value='B'>B</option> </select> <select name='list2[]' id='list2' size='3' onclick='click1(this.id)'> <option value='C'>C</option> <option value='D'>D</option> </select> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/46828-multiple-select-list-issue-with-php-and-javascript/#findComment-228295 Share on other sites More sharing options...
jitesh Posted April 13, 2007 Share Posted April 13, 2007 <select name='list1[]' id='list2' size='3' onclick='click1(this.id)' multiple> <select name='list2[]' id='list2' size='3' onclick='click1(this.id)' multiple> Link to comment https://forums.phpfreaks.com/topic/46828-multiple-select-list-issue-with-php-and-javascript/#findComment-228298 Share on other sites More sharing options...
jwhite68 Posted April 18, 2007 Author Share Posted April 18, 2007 Hi Barand. I have tried applying your idea to my situation, but expect I cant fully grasp the concept. Can you give any more clues to how this applies to my situation, as I am not so strong in PHP? Link to comment https://forums.phpfreaks.com/topic/46828-multiple-select-list-issue-with-php-and-javascript/#findComment-231995 Share on other sites More sharing options...
Barand Posted April 18, 2007 Share Posted April 18, 2007 Iy's a js solution, not PHP Instead of referencing the dropdowns using " obj = document.formname.list2[] ", which it doesn't like, use the id with obj = document.getElementByID("list2"); Link to comment https://forums.phpfreaks.com/topic/46828-multiple-select-list-issue-with-php-and-javascript/#findComment-232364 Share on other sites More sharing options...
jwhite68 Posted April 18, 2007 Author Share Posted April 18, 2007 Thanks. I have now set this. My issue now is that when I try to look at the value of 'list2', it appears there are no contents. It doesnt see it as an array, and it has no data! Link to comment https://forums.phpfreaks.com/topic/46828-multiple-select-list-issue-with-php-and-javascript/#findComment-232381 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.