title: set one textbox value dynamically while change on another textbox in jquery
body: <p>I am trying to do something like asp.net textchanged event using jquery. when i change one tetbox value using autocomplete there will be change on another textbox . data will come from my database. suppose i have  two textbox  txtOne and TxtTwo. when i change txtone using autocomplete txtTwo value will change accorindg to txtOne from database. 
  here is my code. what am i doing wrong? how could i achieve Autocomplete and Textchange event in same textbox in mvc.</p>
  
  <pre><code> @Html.TextBoxFor(model =&gt; model.ITEMNM, htmlAttributes: new { @class = "form-control", id = "txtOne" })
   @Html.TextBoxFor(model =&gt; model.ITEMNM, htmlAttributes: new { @class = "form-control", id = "txtTwo" })
  
  &lt;script language="javascript" type="text/javascript"&gt;
  
      $(document).ready(function () {
          $('#txtOne').autocomplete(
          {
              source: '@Url.Action("TagSearch", "RMS_ITEM")'
          });
      });
  
      $(function () {
          $('#txtOne').change(function () {
              var changedText = $("#txtOne").val();
  
              $.post('@Url.Action("ItemNameChanged","RMS_ITEM")', { "ChangedText": changedText });
  
          });
      });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>here is my controller code</p>
  
  <pre><code>[HttpPost]
  public ActionResult ItemNameChanged(string changedText)
  {
      var result = (from n in db.PosItemMstDbSet
                    where n.CATNM == changedText
                    select new
                    {
                        catid = n.CATID
  
                    }
                  );
  
      foreach (var n in result)
      {
          ViewBag.itemId = n.catid;
      }
      //return changedText + " was submitted!";
      return null;
  }
  
  public JsonResult TagSearch(string term)
  {
      var compid = Convert.ToInt16(System.Web.HttpContext.Current.Session["loggedCompID"].ToString());
  
  
      var tags = from p in db.PosItemMstDbSet
                 where p.COMPID == compid
                 select p.CATNM;
  
      return this.Json(tags.Where(t =&gt; t.StartsWith(term)),
                      JsonRequestBehavior.AllowGet);
  }
  </code></pre>