Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in below code it is working for names but while im entering character searchbox fill with mulitple names and when i select that name and while i click submit button tahrt valuses taking other id values




XML
@model AppModels.Models.DocDto

@{
    ViewBag.Title = "AutoCompleteCountry";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<div class="form-horizontal" id="formulario">
    <div class='control-group'>
        <label class="control-label" style="font-size: 18px; width: 250px;">Search doctor by name</label>
        <div class='controls' style="margin-left: 280px;">
        <input class="input-xlarge" type="text" id="FName"  name="somevalue" data-autocomplete-url="@Url.Action("AutoCompleteCountry/Home")"/>

            <input type="submit" id="CustomersList" value="Submit"/>
        </div>
    </div>
</div>





<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery-ui-1.9.2.min.js"></script>
@Styles.Render("~/Content/themes/base/css")


<script type="text/jscript">
    var b;
    alert(b)
    $('#CustomersList').click(function () {

            alert(b)
         var fname = b;
         var url = '@Url.Action("DoctorList")/' + fname;

         $.get("@Url.Action("DoctorList")/" + fname, function (a) {

             $('#div1').html(a);

            });

});</script>




<script type="text/javascript">
    $(document).ready(function () {
        $("#FName").autocomplete({
            source: function(request,response) {
                $.ajax({

                    url:"@Url.Action("AutoCompleteCountry")",
                    type: "POST",
                    dataType: "json",
                    data: { term: request.term },
                    success: function (data) {
                        response($.map(data, function (item)


                        {
                            b = item.DID;


                            alert(b)

                         return {
                                label: item.FName +
                                         item.LName + " "
                                         + item.Photo + item.Address
                                , value: item.FName
                                , id: item.FName,


                                    //id:item.DID


                          };



                        }))

                    }
                })
            },
            messages: {
                noResults: "", results: ""
            }
        });
    })
</script>

<div id="div1" style="height:auto;margin-left:100px;margin-top:10px;width:auto;">






</div>
Posted

1 solution

Instead of having troubles with your own code, you could Twitter typeahead/[^]. It would be far more covinient
 
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