我有这个脚本来获取下拉列表的文本
<script>
function streetvalue(data) {
var i = street.selectedIndex;
if (i != -1) {
document.getElementById("street2").value = street.options[i].text;
}
}
</script>
这是我的HTML
<tr>
<td width="120" height="30" class="label"><label for="accno"><strong>Street/Alley</strong></label></td>
<td height="30" class="content">
<select name="street" id="street" style="width:200px;" onchange="streetvalue(this)" required>
<option value="" label="Select your street">Select your street</option>
<?php
$sql = "SELECT * FROM tblstreet ORDER BY lname asc";
$result = dbQuery($sql);
while($row = dbFetchAssoc($result)) {
echo '<option value="'.$row['lid'].'">'.$row['lname'].'</option>';
}
?>
</select>
<input type="text" id="street2">
从下拉列表中选择项目时,它正常工作,文本框会复制它。但是当我点击提交并将其保存到我的数据库时,我的数据库中始终显示的值是&#34; street2&#34;而不是我在下拉列表中选择的文字。我错过了什么吗?谢谢你的帮助!
当按下提交按钮时,这是我的功能
function doRegister()
{
$fname = $_POST['firstname'];
$mname = $_POST['middlename'];
$lname = $_POST['lastname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$cphone = $_POST['cphone'];
$dob = $_POST['dob'];
$job_type = $_POST['intext4'];
$street2 = $_POST['street2'];
$sql = "INSERT INTO tbl_address (user_id, blknum, apartment, street, street2, subdivision, city, zipcode, res_type, address)
VALUES ($insert_id, '$blknum', '$apart', '$street', 'street2', '$subdi', '$city', '$zip', '$typeres', '$address')";
dbQuery($sql);
街道字段是我的下拉菜单,street2字段是下拉菜单中的复制文本。谢谢!