我有这个让我很困惑的学校项目(虽然看起来很简单)。所以这是交易,我需要根据组合框的选择设置文本框的值。这是我到目前为止得到的
<?php require_once( str_replace('//','/',dirname(__FILE__).'/') . 'library/SfCrud.php' );
$sfCrud = new SfCrud();
$resultSupplier = $sfCrud->read('select * from supplier');
?>
<form action="" method="post">
<div align="center">
<table>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3">Supplier Information</td>
</tr>
<tr>
<td>Supplier </td>
<td>:</td>
<td>
<select style="width:100%" id='slcSupplier' name="slcSupplier">
<?php foreach($resultSupplier as $row){?>
<option value="<?php echo($row->supplierID);?>"> <?php echo($row->supplierID.' : '.$row->name);?>
</option> <?php }?>
</select>
</td>
</tr>
<tr>
<td>Address</td><td>:</td>
<td> <textarea id="txtAddress" name="txtAddress"></textarea> </td>
</tr>
</table>
</form>
我需要从数据库中获取所选供应商的地址,并将其显示在文本区域而不刷新整个页面..感谢您的帮助..
阅读答案后,我重新编写了代码
<?php require_once( str_replace('//','/',dirname(__FILE__).'/') . 'library/SfCrud.php' );
$sfCrud = new SfCrud();
$resultSupplier = $sfCrud->read('select * from supplier');
?>
<script>
$(document).ready(function(e)
{
$("#slcSupplier").change(function(){
var id = $(this).val();
$.ajax({
url: 'supplier.php',
method: 'POST',
data: "id=" + id,
success: function(data)
{
$('#txtAddress').html(data);
}
});
});
});
</script>
<div>
<table>
<tr>
<td colspan="3">
<input type="button" name="a" id="a" value="Submit" /></td>
</tr>
<tr>
<td colspan="3">Supplier Information</td>
</tr>
<tr>
<td>Supplier </td>
<td>:</td>
<td>
<select style="width:100%" id='slcSupplier' name="slcSupplier">
<?php foreach($resultSupplier as $row){?>
<option value="<?php echo($row->supplierID);?>">
<?php echo($row->supplierID.' : '.$row->name);?>
</option> <?php
}?>
</select>
</td>
</tr>
<tr>
<td>Address</td><td>:</td>
<td>
<textarea id="txtAddress" name="txtAddress"></textarea>
</td>
</tr>
</table>
我不知道出了什么问题,但是javascript不起作用..我在这里很无能为力..