Jump to content

Moving Values Between Select Boxes


ksmatthews

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/72799-moving-values-between-select-boxes/
Share on other sites

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

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.

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

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> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.