当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How to populate input text fields with values from database on checkbox clicked

问题描述:

I am trying to automatically populate multiple input text fields with the values of variables returned from SELECT query on click checkbox event. For example: the SELECT query returns Warehouse Street Address ($WarehouseStreetAdress). Then after checking the checkbox "Use the Warehouse Street Address"this address should be entered into input text field. I have the following code:

$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);

}

网友答案:

I think that you mixed PHP with 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>
分享给朋友:
您可能感兴趣的文章:
随机阅读: