当用户选择客户名称时,我想在运行时从数据库中填写该客户的地址和城市。因为我在更改时调用 javascript 函数,然后我正在调用 php 函数 addfun() 并尝试从中传递查询的键值。我写了下面的代码,但那不起作用。
<script language='javascript' type='text/javascript'>
function ILovePHP(frm, a) {
var formName = frm.name;
alert(formName);
b=<?php addfun(formName,a);?>;
alert(b);
}
</script>
<?php
$attrs = array("onChange" => "ILovePHP(this.form, this.value);");
require_once "HTML/QuickForm.php";
require_once "HTML/QuickForm/Renderer.php";
$form = new HTML_QuickForm('customer_master', 'post');
$form->addElement('select','custName','Select Customer Name',$cnameAry,$attrs);
$form->addElement('text', 'custAdd', 'Customer Address');
$form->addElement('text','custCity', 'City');
$form->addElement('text','custState', 'State');
$form->display();
function addfun($frm, $p)
{
$query="Select Address, City from entityMaster where eid=$p ";
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('GenInsurance');
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$frm->setDefaults(array( 'custAdd' => $row['Address']));
$frm->setDefaults(array( 'custCity' => $row['Address']));
print $frm;
return $frm;
}
?>