locked
Javascript problems RRS feed

  • Question

  • User-1995896158 posted

    Hi, I am working on this solution in asp.net MVC I have 3 models, one with customers one with customer contacts, and one with the order. I would like to make sure that after selecting the customer, a selection of contacts for that customer appears

    <div class="input-group input-group-sm mb-3">
    <div class="input-group-prepend">
    <span class="input-group-text" id="inputGroup-sizing-sm">Ditta:</span>
    </div>
    @{
    var listaOggetti = new List<SelectListItem>();
    foreach (Cliente c in listaDitte)
    {
    var oggetto = new SelectListItem();
    oggetto.Text = c.Nome;
    oggetto.Value = "" + c.ID;
    listaOggetti.Add(oggetto);
    }
    @Html.DropDownList("Cliente", listaOggetti, new { @class = "form-control", aria_describedby = "inputGroup-sizing-sm", name = "sel"
    , @onchanghe = "aggiorna()", aria_label = "Sizing example input" })
    }
    </div>
    <INPUT name="sel_value" value="1">
    <INPUT name="sel_text" value="12">

    this is how i populate the list

    this is the scrip that i tryied to use 

    function aggiorna(sel) {
    var f = document.frm;
    f.sel_value.value = sel.options[sel.selectedIndex].value;
    f.sel_text.value = sel.options[sel.selectedIndex].text;
    }

    but nothing append

    Monday, September 30, 2019 8:54 AM

Answers

  • User665608656 posted

    Hi jacopoFabbri,

    According to your description, do you want to achieve cascading function between two dropdownlists?

    If so,you can refer to this link for your reference:

    Cascading Dropdownlist using Ajax in Asp.Net Mvc 4

    This example is how to realize the cascade relationship between multiple dropdownlists in mvc.

    By modifying the selection of the first dropdownlist, the data source of the second dropdownlist changes accordingly.

    Best Regards,

    YongQing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 1, 2019 3:26 AM

All replies

  • User665608656 posted

    Hi jacopoFabbri,

    According to your description, do you want to achieve cascading function between two dropdownlists?

    If so,you can refer to this link for your reference:

    Cascading Dropdownlist using Ajax in Asp.Net Mvc 4

    This example is how to realize the cascade relationship between multiple dropdownlists in mvc.

    By modifying the selection of the first dropdownlist, the data source of the second dropdownlist changes accordingly.

    Best Regards,

    YongQing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 1, 2019 3:26 AM
  • User-1995896158 posted

    thks for the answer was perfect, but there is a way for doing the same thing without using js?

    Tuesday, October 1, 2019 8:29 AM