Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 641941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:07:02+00:00 2026-05-13T21:07:02+00:00

I have three cascaded drop down lists. ddlIllnessType, ddlIllnessSubType and ddlInfectiousAgent Initially, only ddlIllnessType

  • 0

I have three cascaded drop down lists.

ddlIllnessType, ddlIllnessSubType and ddlInfectiousAgent

Initially, only ddlIllnessType is showing. On change, ddlIllnessSubType is filled with json data and made visible. So far, so good.

Next, when the user selects a value from ddlIllnessSubType, a similar procedure runs for ddlInfectiousAgent in the ddlIllnessSutType change event handler. However, in the following code, $(this).val() always comes up as ‘undefined’, even though the user has chosen an existing value:

$("#ddlIllnessSubType").change(function() {

var selection = $(this).val();

// go and get Json based on the value of selection.  
// Doesn't work cos selection == 'undefined'
var url = "/IllnessDetail/CascadedDdlInfectiousAgent/" + selection;

getJSON(url, function(data) {...});
...
});

Why is selection == ‘undefined’?????!

Thanks in advance

Andrew

PS: The full jQuery and the HTML are as follows:

The full jQuery code is:

<script type="text/javascript">

    $('document').ready(function() {
        var pEst = $("#pEncephalitisSubType");
        var pIa = $("#pInfectiousAgent");
        var ddlEst = $("#IdEncephalitisSubType");
        var ddlIa = $("#IdInfectiousAgent");

        $('#SubTypeContainer').hide();

        pEst.hide();
        pIa.hide();
//        debugger
        $('select').each(function() {
            $(this).val(""); //alert($(this).val()); 
        });

        // Change Event Handler
        $("#IdEncephalitisType").change(function() {
            var selection = $(this).val();
            pEst.fadeOut('slow');
            pIa.fadeOut('slow');
            ddlEst.val("");
            ddlIa.val("");

            if (selection == 0) {
                $('#SubTypeContainer').fadeOut('slow');
            }
            else {
                var url = "/Members/IllnessDetail/CascadedDdlSubType/" + selection;
                AjaxEncephalitisSubTypes(url);
            }
        });

        // Change Event Handler
        $("#IdEncephalitisSubType").change(function() {
            var selection = $(this).val();
            debugger
            pIa.fadeOut('slow');
            ddlIa.val("");
            if (selection != "") {
                if (($("#IdEncephalitisType").val() == 1) && ((selection == 1) || (selection == 2))) {
                    var url = "/Members/IllnessDetail/CascadedDdlInfectiousAgent/" + selection;
                    AjaxInfectiousAgents(url);
                }
            }
        });

        function AjaxEncephalitisSubTypes(url) {
            $('#SubTypeContainer').fadeOut('slow');
            $.getJSON(url, null, function(json) {
                ddlEst.empty();
                ddlIa.empty();
                PrependDdlDefaults(ddlEst);
                var i = 0;
                $.each(json, function(index, optionData) {
                    ddlEst.append("<option value='"
                        + optionData.EncephalitisSubTypeId
                        + "'>" + optionData.Name
                        + "</option>");
                    i++;
                });
                $('#SubTypeContainer').fadeIn('slow');
                ddlEst.val("");
                pEst.fadeIn('slow');
            });
        }

        function AjaxInfectiousAgents(url) {
            $('#SubTypeContainer').fadeOut('slow');
            $.getJSON(url, null, function(data) {
                var i = 0;
                ddlIa.empty();
                PrependDdlDefaults(ddlIa);
                $.each(data, function(index, optionData) {
                    ddlIa.append(
                    "<option value='"
                    + optionData.InfectiousAgentId
                    + "'>" + optionData.Name
                    + "</option>");
                    i++;
                });
            });
            ddlIa.val("");
            $('#SubTypeContainer').fadeIn('slow');
            pIa.fadeIn('slow');
        }

        function PrependDdlDefaults(ddl) {
            ddl.prepend(
                "<option value='"
                + ""
                + "'><i>" + " --- Please choose... --- "
                + "</i></option>");
        }
    });


</script>


<fieldset>
    <legend>The Illness</legend>
    <p>
        According to your input, different drop down lists will appear, specialised to only
        show the options that apply.
    </p>
    <p>
        <label for="IdEncephalitisType">
            Type Of Encephalitis:</label>
        <%= Html.DropDownList("IdEncephalitisType", Model.EncephalitisTypes)%>
        <%= Html.ValidationMessage("IdEncephalitisType", "*") %>
    </p>
    <div id="SubTypeContainer" style="margin-left:10px;border: solid 1px #ccc; background: #efefef;">
        <p class="highlight" id="lblSubTypeContainer" style="font-weight:bold;color:#c00;">
            Extra Information regarding the Illness:</p>
        <p id="pEncephalitisSubType">
            <label id="lblEncephalitisSubType" for="IdEncephalitisSubType">
                Sub Type of Encephalitis:</label>
            <%= Html.DropDownList("IdEncephalitisSubType", Model.EncephalitisSubTypes)%>
            <%= Html.ValidationMessage("IdEncephalitisSubType", "*") %>
        </p>
        <p id="pInfectiousAgent">
            <label id="lblInfectiousAgent" for="IdInfectiousAgent">
                Infectious Agent:</label>
            <%= Html.DropDownList("IdInfectiousAgent", Model.InfectiousAgents) %>
            <%= Html.ValidationMessage("IdInfectiousAgent", "*") %>
        </p>
    </div>
</fieldset>

The controller doesn’t need to be shown, as the json delivered is correct. As in I’ve tested it and what gets rendered is correct.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:07:03+00:00Added an answer on May 13, 2026 at 9:07 pm

    Cracked it!!!!!!

    The problem was in the json callback:

    $.each(json, function(index, optionData) {                    ddlEst.append("<option value='"                        + optionData.Id                        + "'>" + optionData.Name                        + "</option>");                    i++;                });
    $.each(json, function(index, optionData) {
                        ddlEst.append("<option value='"
                            + optionData.Id
                            + "'>" + optionData.Name
                            + "</option>");
                        i++;
                    });
    

    …where optionData.Id is not the right name for the field! Oh, **&^%$£”!¬

    As a result, all the tags had the following value:

    value="undefined"
    

    AAAAAAAARRRRRRGGGGGGJJJHHHHHH!!!!!!!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have three lists with the same number of elements in each other, i
I have three drop downs in my VBA form ( cbo_fac1 , cbo_fac2 ,
Have three classes User, Group and Field. Many to many relationship on User /
Have three divs in a container that I want to float over a large
I have three separate table variables in my Function, 1 of them is not
I have three files: lib.c lib.h => They should be built as a .so
i have three java based web application app1,app2 and app3 at production. All 3
I have three tables. I have to retrieve the data using Linq statement. My
I have three divs, within a content div. Container width 70%. Within that I
I have three tables (individuals, groups & recordlabels) and want use the information between

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.