Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
XML
<script type="text/javascript">

    $('#GLGroupCode').on('change', function (event) {
        alert("s");
        $.ajax({ url: "/GLMaster/TextChanged", type: "GET", data: { text: $('#GLGroupCode').val() }, dataType: 'json', success: function (result) {
            $('#txtSearch1').val(result);
        }
        });
    });

</script>


@Html.TextBoxFor(model => model.GLGroupName, new { id = "txtSearch1" })
@Html.ValidationMessageFor(model => model.GLGroupName)


@Html.LabelFor(model => model.GLSubGroupCode)


@Html.TextBoxFor(model => model.GLSubGroupCode, new { id = "txtSearchgrp" })
@Html.ValidationMessageFor(model => model.GLSubGroupCode)


C#
public JsonResult TextChangedTextChanged(string term)
       {


              var subGroups =  from p in  db.tblGLGroups where p.GroupCode== term  select p.GroupName;

           return Json(subGroups, JsonRequestBehavior.AllowGet);
       }
Posted
Updated 13-Nov-15 21:54pm
v2
Comments
BillWoodruff 14-Nov-15 3:51am    
This is a JavaScript question, not a C# question.

1 solution

Instead of change, make it to keyup or onfocusout :
JavaScript
<script type="text/javascript">
    $('#GLGroupCode').on('keyup', function (event) {
        alert("s");
        $.ajax({ url: "/GLMaster/TextChanged", type: "GET", data: { text: $('#GLGroupCode').val() }, dataType: 'json', success: function (result) {
            $('#txtSearch1').val(result);
        }
        });
    });
 </script>


-KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900