here's the code dropdown and textbox:
<form id="myForm">
<label for="departmentsDropdown">Department</label>
<select class="form-control" onchange="getValue()"
id="numero_control" name="numero_control">
</select><br />
<input type="text" value="" id="Nombre" /><br>
<input type="text" value="" id="id" /><br>
</form>
function onchange:
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<div class="jumbotron">
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "GET",
url: "/Home/GetData",
data: "{}",
success: function (data) {
var s = '<option value="-1">Porfavor selecciona algun valor</option>';
for (var i = 0; i < data.length; i++) {
s += '<option value="' + data[i].Nombre + data[i].id + '">' +
data[i].numero_control + '</option>';
}
$("#numero_control").html(s);
}
});
});
function getValue() {
var myVal = $("#numero_control").val();
$("#Nombre").val(myVal);
$("#id").val(myVal);
}
</script>
</div>
Controller action method:
crudEntities db = new crudEntities();
public ActionResult Index()
{
return View();
}
public ActionResult GetData()
{
var data = from als in
db.registro select new
{ als.id, als.Nombre,als.numero_control };
return Json(data.ToList(),
JsonRequestBehavior.AllowGet);
}
What I have tried:
my error is I have two value in the dropdown i was load in two textbox the problem is if i run the project watch the two value in one textbox input:
Image of the error
I would like it to come out like this: I have information such as id, Nombre, numero_control. When I choose the numero_control from the dropdown, I want to print id on one of the 2 textboxes and id on the other textbox.
I followed this video to do it.