Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
here's the code dropdown and textbox:

ASP.NET
<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:
ASP.NET
<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:

ASP.NET
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.
Posted
Updated 22-Aug-21 1:39am

1 solution

Haha same problem i have i follow the same tutorial
 
Share this answer
 
Comments
Richard Deeming 23-Aug-21 4:50am    
"Me too" is not a solution to anyone's question.

If you want to post a comment to the question, click the "Have a Question or Comment?" button under the question and post a comment.

Do not post your comment as a "solution".

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