Posts

Showing posts from April, 2009

jQuery and MVC Autosuggest while saving the selected Id

Yea, I know, boring title. But I really want to make sure I can find the code for how to do this one.

jQuery is very cool. All the eye candy is nice, the syntax is excellent, but the real benefit is AJAX...

The autocomplete jQuery library is extremely nice. It allows you to take a Json result from some url and suggest results to a text box. What I want is for the selected value to populate another input field (hidden) so that I have a real foreign key relationship to the item they selected.

here's the html:
<input class="location" id="LocationName"> <input id="LocationId" type="hidden" keyFor="LocationName"/> Or alternately you can use Html Helpers<%= Html.TextBox("LocationName", null, new {class = "location"}) %> <%= Html.Hidden("LocationId", null, new {keyFor = "LocationName"})%> and here is the supporting javascript:$(document).ready(function() { $('.location).au…