我有一个带有选择标签的表单;从下拉列表中选择项目时,其余的表单字段应相应填写。请注意,所有表单数据均来自 mysql 数据库。下面是我的代码:
<script language="javascript" type="text/javascript">
function populateData($id)
{
alert('in populateData');
y = document.getElementById("selectCard");
document.getElementById("to_address").value = to_address[y.selectedIndex];
document.getElementById("subject").value = subject[y.selectedIndex];
document.getElementById("email_content").value = email_content[y.selectedIndex];
}
</script>
<body>
<?php
mysql_connect("localhost", "someUser", "password") or die("Connection Failed");
mysql_select_db("mns")or die("Connection Failed");
$query = "SELECT * FROM table";
$result = mysql_query($query);
?>
<select id="selectCard" class="dropdown" onchange="populateData($id)">
<?php
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line['source_name'];?>"> <?php echo $line['source_name'];?>
<?php
$id = $line['source_id'];
$source_name = $line['source_name'];
$source_email = $line['source_email'];
$phone_no = $line['source_id'];
$disteller_function = $line['disteller_function'];
}
?>
</select>
<P><INPUT ID="to_address" TYPE="TEXT" NAME="to_address" SIZE="25"></P>
<P><INPUT ID="subject" TYPE="TEXT" NAME="subject" SIZE="25"></P>
<P><INPUT ID="email_content" TYPE="TEXT" NAME="email_content" SIZE="500"></P>
<P><INPUT TYPE="SUBMIT" VALUE="Submit" NAME="B1"></P>
</body>
当我将'$id' 作为参数传递时,'populateData($id)' 函数不会被调用。当我删除参数时,代码可以工作,但我在其余的表单字段中得到'undefined'。
任何帮助深表感谢。
七无