php和js下拉菜单联动
有一个下拉菜单,是从数据库读值的,一个文本框显示我所选择的下拉列表的值我的代码如下,但是不起作用,求帮忙看看问题在哪<html><head><title>TornadoP...
有一个下拉菜单,是从数据库读值的,一个文本框显示我所选择的下拉列表的值
我的代码如下,但是不起作用,求帮忙看看问题在哪
<html>
<head><title>Tornado Prediction</title></head>
<?php
$link=pg_connect("host=localhost port=5432 dbname=ms user=postgres password=123456") or die("fail to connect");
?>
<script type = "text/javaScript">
function changestate()
{
//var length=document.myform.state.length;
var state_list=document.getElementByName("state");
var selected_state=state_list.options[state_list.selectedIndex].text;
document.getElementById("ssss").value=selected_state;
//var oOption = document.createElement("county");
}
</script>
<body>
<form name="myform">
</br><th>Select State<select name='state' onchange="changestate()">
<option value='1' selected>please select</option>
<?php
/*select state*/
$sql_state="SELECT DISTINCT state from county order by state";
$result_state=pg_query($link,$sql_state);
if(!$result_state)
echo "search fail";
while($row_state=pg_fetch_array($result_state))
{
echo '<option value='.$row_state['state'].'>'.$row_state['state'].'</option>';
echo "</br>";
}
?>
</select></th></br>
<p>选择的州是:<input type="text" id="ssss" size="20"></p>
</form>
</body>
</html>
现在第一个下拉列表可以正常从数据库读值,就是当我在里面选择了,下面的文本框一直没有值出来 展开
我的代码如下,但是不起作用,求帮忙看看问题在哪
<html>
<head><title>Tornado Prediction</title></head>
<?php
$link=pg_connect("host=localhost port=5432 dbname=ms user=postgres password=123456") or die("fail to connect");
?>
<script type = "text/javaScript">
function changestate()
{
//var length=document.myform.state.length;
var state_list=document.getElementByName("state");
var selected_state=state_list.options[state_list.selectedIndex].text;
document.getElementById("ssss").value=selected_state;
//var oOption = document.createElement("county");
}
</script>
<body>
<form name="myform">
</br><th>Select State<select name='state' onchange="changestate()">
<option value='1' selected>please select</option>
<?php
/*select state*/
$sql_state="SELECT DISTINCT state from county order by state";
$result_state=pg_query($link,$sql_state);
if(!$result_state)
echo "search fail";
while($row_state=pg_fetch_array($result_state))
{
echo '<option value='.$row_state['state'].'>'.$row_state['state'].'</option>';
echo "</br>";
}
?>
</select></th></br>
<p>选择的州是:<input type="text" id="ssss" size="20"></p>
</form>
</body>
</html>
现在第一个下拉列表可以正常从数据库读值,就是当我在里面选择了,下面的文本框一直没有值出来 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询