By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,960 Members | 1,009 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,960 IT Pros & Developers. It's quick & easy.

drop down list

P: 1
Hi..

I have a drop down list in a page..

I have to select multiple values and
that selected values should be displayed in another drop down list after this drop down list
Mar 28 '12 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,031
sorry, my answer has nothing to do with PHP....

but below code show how this can be done with javascript (i'm not good in javascript )

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <head>
  3.     <script type="text/javascript">
  4.       function doit() {
  5.         x = document.getElementById("cars");
  6.         y = document.getElementById("cars2");
  7.         for (f=y.options.length-1; f>=0; f--) {
  8.           y.options[f].value = '';
  9.           y.options[f].text = '';
  10.           y.options[f] = null;
  11.         }
  12.         for (f=0; f<x.options.length; f++) {
  13.           if (x.options[f].selected) {
  14.             ynew = document.createElement('option');
  15.             ynew.text = x.options[f].text;
  16.             ynew.value = x.options[f].value;
  17.             y.add(ynew,0);
  18.           }
  19.         }
  20.       }
  21.     </script>
  22.   </head>
  23.   <body>
  24.  
  25.     <form onclick="doit()" name="form">
  26.       <select multiple="multiple" id="cars">
  27.           <option value="volvo">Volvo</option>
  28.             <option value="saab">Saab</option>
  29.               <option value="opel">Opel</option>
  30.                 <option value="audi">Audi</option>
  31.         </select>
  32.       </form>
  33.  
  34.       <select id="cars2" multiple="multiple">
  35.       </select>
  36.   </body>
  37. </html>
Mar 29 '12 #2

Dormilich
Expert Mod 5K+
P: 8,639
first you would need to read the dropdown’s values as array (i.e. give it a name with [] at the end). then you should have all selected values available in PHP and you can build your other dropdown.

though it might be better to do that in JavaScript, but that depends on the task.
Mar 29 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.