I’m trying to figure out what I’m doing wrong here. Using autocomplete I’m getting data that’s being returned with JSON data ….
Here’s the JSON data thats returning from the QUERY.
[{"value":"Company Test 1 Manager Test 1 111-111-1111","Company_Name":"Company Test 1","Manager":"Manager Test 1","Phone":"111-111-1111","Contacted":"1"},
{"value":"Company Test 2 Manager Test 2 222-222-2222","Company_Name":"Company Test 2","Manager":"Manager Test 2","Phone":"222-222-2222","Contacted":"0"},
{"value":"Company Test 3 Manager Test 3 333-333-3333","Company_Name":"Company Test 3","Manager":"Manager Test 3","Phone":"333-333-3333","Contacted":"0"},
{"value":"Company Test 4 Manager Test 4 444-444-4444","Company_Name":"Company Test 4","Manager":"Manager Test 4","Phone":"444-444-4444","Contacted":"1"},
{"value":"Company Test 5 Manager Test 5 555-555-5555","Company_Name":"Company Test 5","Manager":"Manager Test 5","Phone":"555-555-5555","Contacted":"0"},]
Now, here’s my JQuery (using JQuery 1.6.2)
<script type="text/javascript">
$(function() {
$('#Company_Name').val("");
$('#Manager').val("");
$('#Phone').val("");
$('#Contacted').val("");
$("#autoSearch").autocomplete({
source: "UPDATE.test001QUERY.php",
minLength: 2,
select: function(event, ui) {
$('#Company_Name').val(ui.item.Company_Name);
$('#Manager').val(ui.item.Manager);
$('#Phone').val(ui.item.Phone);
if ('#Contacted' == [1]) {
$('#Contected').prop('checked', true);
} else {
$('#Contected').prop('checked', false);
}
}
});
});
</script>
What did I do wrong? The autocomplete works fine but the checkbox does not “check” based on the “0” or “1” thats returned from the QUERY.
I think
if ('#Contacted' == [1])should be
if (ui.item.Contacted === "1")Edit,
the first thing you need to do is determine if the
ifstatement in yourselectcallback is being entered under the correct circumstances.if it is, you need to figure out why you are not modifying the right dom. So I see your selector is
#Contected. Are you sure you have a checkbox with anidattributeContected? Should it beContacted?