ugrás a tartalomhoz

Menu tartalmabol tombot kell csinalni

Anonymous · 2006. Aug. 14. (H), 12.02
Adott a kovetkezo kod:
  1. <?php  
  2.   
  3. // Connect and select the database  
  4. require('../includes/mysql.php');   
  5.   
  6. $users = mysql_query("SELECT user_id, username FROM register");  
  7. ?>   
  1. <script language="JavaScript" type="text/javascript">  
  2. <!--  
  3.   
  4. var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);  
  5.   
  6. function addOption(theSel, theText, theValue)  
  7. {  
  8.   var newOpt = new Option(theText, theValue);  
  9.   var selLength = theSel.length;  
  10.   theSel.options[selLength] = newOpt;  
  11. }  
  12.   
  13. function deleteOption(theSel, theIndex)  
  14. {   
  15.   var selLength = theSel.length;  
  16.   if(selLength>0)  
  17.   {  
  18.     theSel.options[theIndex] = null;  
  19.   }  
  20. }  
  21.   
  22. function moveOptions(theSelFrom, theSelTo)  
  23. {  
  24.     
  25.   var selLength = theSelFrom.length;  
  26.   var selectedText = new Array();  
  27.   var selectedValues = new Array();  
  28.   var selectedCount = 0;  
  29.     
  30.   var i;  
  31.     
  32.   // Find the selected Options in reverse order  
  33.   // and delete them from the 'from' Select.  
  34.   for(i=selLength-1; i>=0; i--)  
  35.   {  
  36.     if(theSelFrom.options[i].selected)  
  37.     {  
  38.       selectedText[selectedCount] = theSelFrom.options[i].text;  
  39.       selectedValues[selectedCount] = theSelFrom.options[i].value;  
  40.       deleteOption(theSelFrom, i);  
  41.       selectedCount++;  
  42.     }  
  43.   }  
  44.     
  45.   // Add the selected text/values in reverse order.  
  46.   // This will add the Options to the 'to' Select  
  47.   // in the same order as they were in the 'from' Select.  
  48.   for(i=selectedCount-1; i>=0; i--)  
  49.   {  
  50.     addOption(theSelTo, selectedText[i], selectedValues[i]);  
  51.   }  
  52.     
  53.   if(NS4) history.go(0);  
  54. }  
  55.   
  56. //-->  
  57. </script>  
  1. <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">  
  2. <table width="207" border="0">  
  3.  <tr>  
  4.   <td width="100">  
  5.     <select name="sel1" size="10" multiple="multiple" style="width: 100px">  
  6.     <?php  
  7.     while ($row = mysql_fetch_array($users)) {  
  8.     print "<option value=\"{$row['user_id']}\">{$row['username']}</option>\n";  
  9.     } ?>  
  10.     </select>  
  11.   </td>  
  12.   <td width="48" align="center" valign="middle">    
  13.     <input type="button" value="--&gt;" onclick="moveOptions(this.form.sel1, this.form.sel2);" />  
  14.     <input type="button" value="&lt;--" onclick="moveOptions(this.form.sel2, this.form.sel1);" />  
  15.   </td>  
  16.   <td width="45">  
  17.     <select name="sel2" size="10" multiple="multiple" style="width: 100px">  
  18.     </select>  
  19.   </td>  
  20.   </tr>  
  21. </table>  
  22.   
  23. <input type="submit" name="submit" value="submit" />  
  24. </form>  
A fenti kodnak az eredmenye a kovetkezo kepen lathato: klik ide

Szoval van ket menu. Az elso menu tartalmaza az osszes felhasznalot az adatbazisbol. A masodik menu pedig ures.

Ha atrakok peldaul ket felhasznalot : Zoli, Paul a masodik menube es rakatintok a submit gombra, szeretnek egy tombot csinalni, hogy a ket
felhasznalot hoza tudjam adni kesobb egy user2groups mySQL tablahoz.

Csak arra lennek kivancsi, hogyan tudok a masodik menubol egy tombot csinalni.

Ahogy latszik a masodik menu kodja HTML-ben a kovetkezo (meg akkor is ha atraktam ket usert):
  1. <select name="sel2" size="10" multiple="multiple" style="width: 100px">  
  2. </select>  
Kerek egy kis segitseget, elege neheznek tunik nekem a dolog, es kezdo vagyok. Mit kene modositanom, hogy a masodik menube atrakot nevekbol tombot csinaljak ?
 
1

JS trükközés?

sly · 2006. Aug. 15. (K), 02.26
Ha a postban akarod elküldeni a selcet mezőt akkor js-el ki kell jelölnöd, vagy ha úgy nem megy, akkor - szintén küldés elött - js-el pakold át egy hidden mezőbe és úgy küld.