ksmatthews Posted October 11, 2007 Share Posted October 11, 2007 Hi Gurus, I am Moving Values Between Select Boxes using the following code snippet ... <TABLE BORDER=0> <TR> <TD> <SELECT NAME="list1" MULTIPLE SIZE=10 > <OPTION VALUE="G723">G.723.1</OPTION> <OPTION VALUE="gsm">GSM</OPTION> <OPTION VALUE="g726">G.726-32</OPTION> <OPTION VALUE="adpcm">ADPCM</OPTION> <OPTION VALUE="slin">SLIN</OPTION> <OPTION VALUE="g729">G.729</OPTION> <OPTION VALUE="ilbc">ILBC</OPTION> </SELECT> </TD> <TD VALIGN=MIDDLE ALIGN=CENTER> <INPUT TYPE="button" NAME="right" VALUE=">>" ONCLICK="opt.transferRight()"><BR><BR> <INPUT TYPE="button" NAME="right" VALUE="All >>" ONCLICK="opt.transferAllRight()"><BR><BR> <INPUT TYPE="button" NAME="left" VALUE="<<" ONCLICK="opt.transferLeft()"><BR><BR> <INPUT TYPE="button" NAME="left" VALUE="All <<" ONCLICK="opt.transferAllLeft()"> </TD> <TD> <SELECT NAME="list2" MULTIPLE SIZE=10 > <OPTION VALUE="ulaw">G.711u-Law</OPTION> <OPTION VALUE="alaw">G.711a-Law</OPTION> </SELECT> </TD> </TR> </TABLE> My problem is simple: I want to use PHP to get the values transferred to "list2". I know how to do this by making the select objects as arrays ie list1[] and list2[] BUT if I do that the javascript will not work ! How can you get the items transferred to list2 in php ? Thanks ! Steven M Quote Link to comment https://forums.phpfreaks.com/topic/72799-moving-values-between-select-boxes/ Share on other sites More sharing options...
pocobueno1388 Posted October 11, 2007 Share Posted October 11, 2007 PHP can't do this, so your going to have to stick with javascript. PHP only works server-side meaning it requires a page refresh. Quote Link to comment https://forums.phpfreaks.com/topic/72799-moving-values-between-select-boxes/#findComment-367141 Share on other sites More sharing options...
MadTechie Posted October 11, 2007 Share Posted October 11, 2007 I know how to do this by making the select objects as arrays ie list1[] and list2[] BUT if I do that the javascript will not work ! Really.. never had a problem myself! Quote Link to comment https://forums.phpfreaks.com/topic/72799-moving-values-between-select-boxes/#findComment-367143 Share on other sites More sharing options...
ksmatthews Posted October 11, 2007 Author Share Posted October 11, 2007 HI Again, Consider this code snippet ... <SELECT NAME="list2" MULTIPLE SIZE=10 > <OPTION VALUE="ulaw">G.711u-Law</OPTION> <OPTION VALUE="alaw">G.711a-Law</OPTION> </SELECT> How can I use PHP to access multiple choices without making list2 into an array list2[] ? regards, Steven M Quote Link to comment https://forums.phpfreaks.com/topic/72799-moving-values-between-select-boxes/#findComment-367206 Share on other sites More sharing options...
Psycho Posted October 11, 2007 Share Posted October 11, 2007 You can't. If you can't find a workaround for your javascript, then you could get creative. For example, whenever you use javascript to add/remove items from the list also have the javascript populate a hidden field with the values separated by a delimiter character. But, it sounds as if you need to be looking for a solution for the javascript issue - not PHP. Quote Link to comment https://forums.phpfreaks.com/topic/72799-moving-values-between-select-boxes/#findComment-367231 Share on other sites More sharing options...
ksmatthews Posted October 13, 2007 Author Share Posted October 13, 2007 Hi mjdamato, You said: For example, whenever you use javascript to add/remove items from the list also have the javascript populate a hidden field with the values separated by a delimiter character. I thought of that too - a javascript solution. But how would this be implemented ? How do you get javascript to communicate with a php variable ? regards, Steven M Quote Link to comment https://forums.phpfreaks.com/topic/72799-moving-values-between-select-boxes/#findComment-368469 Share on other sites More sharing options...
Barand Posted October 13, 2007 Share Posted October 13, 2007 try <?php if (isset($_GET['sub'])) { echo '<pre>', print_r($_GET['selb'], true), '</pre>'; } ?> <script> function moveMe(i) { var sela = document.getElementById("sela"); var selb = document.getElementById("selb"); var v = sela.options[i].value; if (v=='') return; var t = sela.options[i].text; var k = selb.options.length; var o = new Option(t,v); selb.options[k] = o; selb.options[k].selected = true; sela.options[i] = null; } </script> <form> <select name="sela" id="sela" size="6" onchange="moveMe(this.selectedIndex)"> <option value=""></option> <option value="aaa">aaa</option> <option value="bbb">bbb</option> <option value="ccc">ccc</option> <option value="ddd">ddd</option> <option value="eee">eee</option> </select> <select name="selb[]" id="selb" multiple size="5"> </select> <input type="submit" name="sub" value="Submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/72799-moving-values-between-select-boxes/#findComment-368481 Share on other sites More sharing options...
ksmatthews Posted October 13, 2007 Author Share Posted October 13, 2007 Thanks Barand that is really helpful, Steven M Quote Link to comment https://forums.phpfreaks.com/topic/72799-moving-values-between-select-boxes/#findComment-368580 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.