在两个选择框之间移动选项,php jquery

时间:2014-01-26 02:19:49

标签: javascript php jquery html forms

嗨伙计请帮助我这个我不知道如何开始将此功能发送到php数据库。请帮助我,我需要将正确的框发送到数据库tnx jquery的功能正在工作,但我想不出如何将此插入数据库请帮助我这个:) tnx所有移动选项(文本)两个下一个框并插入php数据库。

select.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Jquery move listbox items from left to right example</title>
  <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
   <script language="javascript" type="text/javascript">



function move_list_items(sourceid, destinationid)
{
    $("#"+sourceid+"  option:selected").appendTo("#"+destinationid);
}

//this will move all selected items from source list to destination list
function move_list_items_all(sourceid, destinationid)
{
    $("#"+sourceid+" option").appendTo("#"+destinationid);
}

    </script>

    <style type="text/css">
       select {
      width:200px;
      height:100px;
    }
    </style>
     </head>

     <body>
     <form action="submit.php" method="post">
     <table cellpadding="5" cellspacing="5">

     <tbody>

     <tr>

       <td colspan="2">
             <select id="from_select_list" multiple="multiple" name="from_select_list"> 
             <option value="apple">Apple</option><option value="mango">Mango</option> <option value="bannana">Bannana</option> <option value="grapes">Grapes</option> 
       </select>
    </td>

    <td colspan="2">
        <select id="to_select_list" multiple="multiple" name="to_select_list"> 
        <option value="winder">Winter</option> <option value="summer">Summer</option>     <option value="rainy">Rainy</option> <option value="Spring">Spring</option> 
        </select>
    </td>

    </tr>

    <tr>

    <td><input id="moveright" type="button" value="Move Right"       onclick="move_list_items('from_select_list','to_select_list');" /></td>

    <td><input id="moverightall" type="button" value="Move Right All" onclick="move_list_items_all('from_select_list','to_select_list');" /></td>

    <td><input id="moveleft" type="button" value="Move Left" onclick="move_list_items('to_select_list','from_select_list');" /></td>

<td><input id="moveleftall" type="button" value="Move Left All" onclick="move_list_items_all('to_select_list','from_select_list');" /></td>

 <input type="submit" name="submit" />
 </tr>

 </tbody>

 </table>
 </body>
 </html>

connection.php
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$db = "copy";
$conn = mysqli_connect($dbhost,$dbuser,$dbpass,$db);
?>


submit.php
<?php
include 'connection.php'
?>

1 个答案:

答案 0 :(得分:0)

将选择选项名称更改为数组,然后只有您可以获取所有选定的项目

<td colspan="2">
    <select id="to_select_list" multiple="multiple" name="to_select_list[]"> 
    <option value="winder">Winter</option> <option value="summer">Summer</option>     <option value="rainy">Rainy</option> <option value="Spring">Spring</option> 
    </select>
</td>
在submit.php中你可以像这样检查

echo '<pre>';
print_r($_POST);