PDA

View Full Version : jquery AutoComplete and AutoFill Issue



jdadwilson
12-14-2013, 10:12 PM
I have a secure web-based application consisting of several modules, one for customer information that contains a form with several input fields. The first field is for the customer code. I have implemented the jquery AutoComplete script for the field. I would also like to implement an AutoFill script so that once the customer code is selected via the AutoComplete (and tabbed to the next field) the remaining fields could be entered by the system. The AutoComplete works just fine but I cannot get the AutoFill to work.

Here is the code…

<head>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$(".auto").autocomplete({
source: "files_json/get_Customers.php",
minLength: 1
});
});
</script>
<script type="text/javascript">
$("#cust_Code").bind("change", function(e) {
$.getJSON("files_json/get_Cust_All.php?custCode=" + $("#cust_Code").val(),
function(data) {
$.each(data, function(i, item) {
if (item.field == "cust_Name") { $("#cust_Name").val(item.value); }
else if (item.field == "cust_Address") { $("#cust_Address").val(item.value); }
});
});
});
</script>
</head>
<body>
<form name="form_edit" id="form_edit" method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
<input class="auto" type="text" name="cust_Code" id= cust_Code" />
<input type="text" name="cust_Name" id="cust_Name" />
<input type="text" name="cust_Address" id="cust_Address" />
</form>
</body>

For testing purposes, the get_Cust_All.php script returns a simple json encoded array as follows…


{"cust_Code":"C002","cust_Name":"All Bases Covered","cust_Address1":"101 Redwood Shores"}

Any assistance that can be provided is greatly appreciated.

jdadwilson