I have a form on my web page in which I need that when a user enters a Code in an input in another input, the Name is auto-completed. I have the code shown below, but it does nothing. I have two tables: TablaCodigos: Codigo_p varchar ...
TablePersonas Codigo_p varchar Name varchar ...
my script
<script type="text/javascript">
$("#Codigo_p").change(function () {
$.getJSON("/Solicitud/GetPersona?Codigo_p=" + $("#Codigo_p").val(), function (result)
{
var select = $("#nombreP");
select.empty();
$.each(result, function (index, itemData) {
select.append($({
value: itemData.Nombre
}));
});
});
}
</script>
my controller
public JsonResult GetPersona(string Codigo_p)
{
bd.Configuration.ProxyCreationEnabled = false;
TablaPersonas nom_p = bd.TablaPersonas.Where(x => x.Codigo_p == Codigo_p).Single();
return Json(nom_p, JsonRequestBehavior.AllowGet);
}
HTML
<div class="form-group">
<div class="m-0 font-weight-bold text-primary subtitulo">Persona:</div>
<input type="text" class="form-control" id="nombreP" name="nombreP" placeholder="Nombre" readonly="" >
</div>