Link to home
Start Free TrialLog in
Avatar of finance_teacher
finance_teacher

asked on

JSON -- populate two textboxes after user SELECTION ?

Currently everything gets saved into
@Html.TextBox("productDescription")
which I do NOT want.

How can I change below code so step #4 populates
@Html.TextBox("productName") with selected c.PartNumber
and @Html.TextBox("productDescription") with its
associated c.PartDescription ?

Steps
 1. user enters data into @Html.TextBox("productName")
 2. search automatically populates @Html.TextBox("productName")
    with possible c.PartNumber --->  c.PartDescription) results
 3. user selects a results
 4. @Html.TextBox("productName") gets updated with
    selected c.PartNumber --->  c.PartDescription)
----------------------------------------------------
AutoCompleteController.cs
        public JsonResult getData(string term)
        {

            var mySearchResults = db.Lookup_PartNumbers
                                    .Where(c => c.PartNumber.Contains(term) || c.PartDescription.Contains(term))
                                    .Select(c => c.PartNumber + "  --->  " + c.PartDescription)
                                    .Take(10);

            return Json(mySearchResults, JsonRequestBehavior.AllowGet);
        }

Open in new window

--------------------------------------------------------------------------------------------------------
Index.cshtm
l
    <script type="text/javascript">
        $(function () {
            $('#productName').autocomplete({
                source: function (request, response) {
                    $.getJSON("/AutoComplete/getData?term=" + request.term, function (data) {
                        response(data);
                    });
                },
                minLength: 2,
                delay: 100
            });
        });
    </script>

Open in new window

               Product: @Html.TextBox("productName")
                Description: @Html.TextBox("productDescription")
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

What does response(data) do?
ASKER CERTIFIED SOLUTION
Avatar of vr6r
vr6r

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial