我正在尝试使用单击复选框事件上的SELECT查询返回的变量值自动填充多个输入文本字段。例如:SELECT查询返回仓库街道地址($ WarehouseStreetAdress)。然后在选中复选框"使用仓库街道地址"此地址应输入到输入文本字段中。我有以下代码:
$WarehouseStreetAddress = $_POST['WarehouseStreetAddress']; ...Select query works fine...
<input id="checkbox" type="checkbox"> Use Warehouse Address<br>
Street Address: <input id="StreetAddress" type="text">
$("#checkbox").change(function() {
if (this.checked) {
var StreetAddress= $WarehouseStreetAdress;
}
$("#StreetAddress").val(StreetAddress);
}
答案 0 :(得分:2)
我认为你将PHP与Javascript混合..
<input id="checkbox" type="checkbox"> Use Warehouse Address<br>
Street Address: <input id="StreetAddress" type="text">
<script type="text/javascript">
$("#checkbox").change(function() {
if (this.checked) {
$("#StreetAddress").val("<?php echo $_POST['WarehouseStreetAddress'];?>");
}
})
</script>