从html下拉列表中获取值,传入javascript函数

时间:2016-11-04 15:18:33

标签: javascript html drop-down-menu html-select

1)用户将在每个列表后单击按钮。 2)点击按钮将所选值发送到javascript函数 3)我想获取javascript函数中的值并使用ajax发送到php文件

问题如何使用onclick将html选定值发送到javascript函数?

<select id="list"> 
      <option value=" ">Select a Name </option>
      <option value="Comfy">Comfy</option>
      <option value="Tough">William Tough </option>
      <option value="Soft">Soft</option>
</select>
<button onclick="updateDB(this.querySelector('list'.selected))">Click Me</button>

<select id="list2"> 
      <option value=" ">Select a Name </option>
      <option value="Comfy">Comfy</option>
      <option value="Tough">William Tough </option>
      <option value="Soft">Soft</option>
</select>
<button onclick="updateDB(this.querySelector('list2'.selected))">Click Me</button>

Javascript功能:

function updateDB(number)
{

 if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
} else {
    // code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

    xmlhttp.open("GET","/updatequery.php?numbers",true);
xmlhttp.send();
}

1 个答案:

答案 0 :(得分:3)

检查OCI上的PHP文档:http://php.net/manual/en/function.oci-execute.php

执行select查询后,您需要从数据库中获取行。

此处的示例应该可以帮助您入门:

<?php

$conn = oci_connect('hr', 'welcome', 'localhost/XE');

$stid = oci_parse($conn, 'SELECT * FROM employees');
oci_execute($stid);

echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
    echo "<tr>\n";
    foreach ($row as $item) {
        echo "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
    }
    echo "</tr>\n";
}
echo "</table>\n";

?>