autocomplete and $.getJSON problem
Posted
by
Dusty Roberts
on Stack Overflow
See other posts from Stack Overflow
or by Dusty Roberts
Published on 2011-01-05T09:49:45Z
Indexed on
2011/01/05
9:53 UTC
Read the original article
Hit count: 334
Hi There
I have a script:
<script type="text/javascript">
$(document).ready(function(){
$("#PrincipleMember_IdNumber").autocomplete({
close: function(event, ui) {
var member = {};
member.IDNumber = $("#PrincipleMember_IdNumber").val();
$.getJSON("<%= Url.Action("MemberLookup","Member") %>", member, function(data) {
$("#PrincipleMember_Firstname").val(data.FirstName);
});
}
});
});
A form:
<fieldset class="fieldsetSection">
<legend>Principle Member</legend>
<table>
<tr>
<td width="150px" class="editor-label"><%=Html.LabelFor(l=>l.PrincipleMember.IdNumber)%></td>
<td class="editor-field"><%= Html.AutoCompleteTextBoxFor(i => i.PrincipleMember.IdNumber, "IdNumber", "AutoComplete")%></td>
<td><%=Html.ValidationMessageFor(v => v.PrincipleMember.IdNumber)%></td>
</tr>
<tr>
<td width="150px" class="editor-label"><%=Html.LabelFor(l=>l.PrincipleMember.Firstname)%></td>
<td class="editor-field"><%=Html.TextBoxFor(t => t.PrincipleMember.Firstname)%></td>
<td><%=Html.ValidationMessageFor(v => v.PrincipleMember.Firstname)%></td>
</tr>
</table>
and finally a json result action:
public JsonResult MemberLookup(Member member)
{
member = _memberRepository.GetMember(member.IDNumber);
return this.Json(member);
}
my json result is executed perfectly and i get a result, but for some reason this section of the script is not executing: $("#PrincipleMember_Firstname").val(data.FirstName);
i've tried replacing it with an alert();
, but that too is not executing.
Can anyone see what i am doing wrong here?
© Stack Overflow or respective owner