使用下拉列表php或javascript中的多个项填充文本框

时间:2011-05-24 03:34:36

标签: php javascript mysql

大家好,我需要对我目前的项目提供一些帮助。 我想要做的是从下拉列表中选择多个数据并将其放在文本框上......只要用户点击下拉列表中的数据,它就会完成。 TIA!更多力量!

。@ Hary - 感谢您的帮助!它确实有效。接下来我要做的是将使用PHP和Mysql查询移动到List2 []的所有选择内容插入到数据库中。

2 个答案:

答案 0 :(得分:0)

试试这个......

<html>
 <body>
   <select multiple="multiple">
    <option value="item1">item1</option>
    <option value="item2">item2</option>
    <option value="item3">item3</option>
    <option value="item4">item4</option>
  </select>
 </body>
</html>

答案 1 :(得分:0)

试试这个:)它有效

<html><head>
<script type="text/javascript">
function OnClkAddButtonServer(form)
{
    var selObj = document.getElementById('List1');
     var selObj2 = document.getElementById('List2[]');

      var i;
      var count = selObj2.options.length;

      for (i=0;i<selObj.options.length;i++) 
      {
         if (selObj.options[i].selected) 
         {
               var option = new Option(selObj.options[i].text,selObj.options[i].value);
               option.title = selObj.options[i].text;
               selObj2.options[count] = option;
               count=count+1;
               selObj.options[i] = null;
               i--;
         }
      }
}
function OnClkRemoveButtonServer(form)
{

     var selObj2 = document.getElementById('List1');
     var selObj = document.getElementById('List2[]');

      var i;
      var count = selObj2.options.length;

      for (i=0;i<selObj.options.length;i++) 
      {
         if (selObj.options[i].selected) 
         {
               var option = new Option(selObj.options[i].text,selObj.options[i].value);
               option.title = selObj.options[i].text;
               selObj2.options[count] = option;
               count=count+1;
               selObj.options[i] = null;
               i--;
         }
      }

}
</script>
</head>


 <body>

   <table>
                  <tr>
                  <td >
                    <table >
                    <tr>
                      <td>Available</td></tr>
                    <tr>
                    <td>
                    <select id="List1" name="List1" size="10" multiple="multiple" style="height: 95px;  width: 225px;   border: 1px solid #535881;  background-color: #f9f9f9;" >
    <option value="item1">item1</option>
    <option value="item2">item2</option>
    <option value="item3">item3</option>
    <option value="item4">item4</option>
                    </select>
                    </td>
</tr>
</table>
</td>
<td >
<table >
<tr>
                    <td  style="padding:5px">

                   <input name="add_usergroupsleftrightselect" value="Add &gt;" class="FormButton" type="button" onclick='OnClkAddButtonServer(this.form)'><br> 

                    <input name="remove_usergroupsleftrightselect" value="&lt; Remove" class="FormButton" type="button" onclick='OnClkRemoveButtonServer(this.form)'><br>


                    </td>
 </tr>
 </table>
 </td>
 <td >
 <table>
 <tr>
   <td>Selected</td></tr>
 <tr>
                    <td>

                    <select id="List2[]" name="List2[]" size="10" multiple="multiple" style="height: 95px;  width: 225px;   border: 1px solid #535881;  background-color: #f9f9f9;">

    <option value="item1">item1</option>
    <option value="item2">item2</option>
    <option value="item3">item3</option>
    <option value="item4">item4</option>         
                      </select>                     
                    </td>
                    </tr>

                    </table>
                    </td>
                    </tr>
                    </table>

 </body>
</html>