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
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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.