在使用ajax提交表单后,我无法正确设置多个文本框上的值,这是我的表单
<form id="searchForm" action="process.php" method="post">
<input id="cust_code" name="cust_code" required>
<input id="cust_code1" name="cust_code1" disabled>
<input id="cust_name" name="cust_name" disabled>
<button type="submit">Search</button>
</form>
process.php
$cust_code = $_POST['cust_code'];
$result = mysql_query("SELECT code,cust_name FROM information WHERE code=$cust_code") or die(mysql_error());
$data = mysql_fetch_array($result);
javascript: var formData = {
'cust_code': $('#cust_code').val()
};
$.ajax({
type : 'POST',
url : 'process.php',
data : formData,
dataType : 'json',
encode : true,
success: function(data) // recieved data from process.php
{
var code = data[0];
var cust_name = data[1];
// Update id value
document.getElementById('cust_code').value = code;
document.getElementById('cust_code1').value = code;
document.getElementById('cust_name').value = cust_name;
}
})
cust_code和cust_code1的值在提交后改变,但cust_name
没有改变任何想法?
编辑:id已经在另一个页面(php include)上使用,因此使输入不会改变,解决!在JQuery中也可以这样赋值:
document.getElementById('cust_code').val(code);
或
document.getElementById('cust_code').attr('value',code);
相同的ID已经在另一个页面(php include)上使用,因此输入值不会改变,将ID更改为cust_names似乎可以做到这一点