我想通过 PHP 将从下拉菜单中选择的区域名称传递给 MySQL 查询。我在 JavaScript 中检索了名称,但无法将值从 JavaScript 存储到 PHP。我的代码如下
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script>
function getIndex()
{
var x=document.getElementById("cmbArea").selectedIndex;
var y=document.getElementById("cmbArea").options
var z= y[x].text;
alert(z);
}
</script>
</head>
<body>
<form name ="form1" action="Demo1.php" method="post">
<select id="cmbArea" name="cmbArea">
<?php
include 'Connect.php';
$query = "SELECT varAreaName FROM tbArea" ;
$result = mysql_query($query);
while($row = mysql_fetch_assoc( $result )) {
echo '<option value="'.$row['varAreaName'].'">' . $row['varAreaName'] . '</option>';
}
?>
</select>
</form>
<input type="Button" onclick="getIndex()" value="Alert index of selected option">
</body>
</html>