Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3 Razor/JQuery Dynamic Form Not works in Firefox
    primarykey
    data
    text
    <p>I have to build up a Razor registration Form with 2 dynamic drop down list fields. The first is a Country field, the second a Region field that must be populated when the first changes. The country list and related region list are stored in my Sql Db. My Razor View looks like this:</p> <pre><code>@model Web.Models.ProfileModel @{ Layout = "~/Views/Shared/_Layout.cshtml"; } @Html.ValidationSummary(true) @using (Html.BeginForm("Register", "Profile", FormMethod.Post, new { id = "RegForm" })) { ... &lt;div class="editor-field"&gt; @Html.DropDownListFor(x =&gt; x.selectedCountry, new SelectList(Model.companyCountry, "Value", "Text"), "Please select a country", new { id = "ddlCountry" }) @Html.ValidationMessageFor(x =&gt; x.selectedCountry) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.companyRegion) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.DropDownListFor(x =&gt; x.selectedRegion, new SelectList(Model.companyRegion, "Value", "Text"), "Please select a region", new { id = "ddlRegion" }) @Html.ValidationMessageFor(x =&gt; x.selectedRegion) &lt;/div&gt; ... } </code></pre> <p>at the bottom of my View I have these scripts. The first is:</p> <pre><code>$("#ddlCountry").change(function () { $("#Loading").empty().html('&lt;img src="../../Content/ajax-loader.gif" /&gt;'); var list = $("#ddlRegion")[0]; list.options.length = 0; var option = new Option("Loading....", 0); list.add(option); var strSelected = ""; $("#ddlCountry option:selected").each(function () { strSelected += $(this)[0].value; }); $.getJSON("UpdateDdlRegion", { id: strSelected }, function (response) { loadDdlRegion(response) } ); $("#Loading").empty(); }); </code></pre> <p>The second here:</p> <pre><code>function loadDdlRegion(response) { var list = $("#ddlRegion")[0]; list.options.length = 0; var option = new Option("@Core.Resources.Resources.ddlregion_msg", ""); list.add(option); for (var i = 0; i &lt; response.length; i++) { var region = response[i]; var option = new Option(region.RegionName,region.Id); list.add(option); } } </code></pre> <p>It seems to work correctly in IE9 and Chrome, but Not in Firefox 5/6! Any idea? I don't know if this is the correct way to implement those drop down lists. If you think in other ways please reply!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload