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

  • Home
  • SEARCH
  • 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 828047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:40:09+00:00 2026-05-15T03:40:09+00:00

I have a webpage with two radiobuttons and a dropdownlist as follows: <div class=sectionheader>Course

  • 0

I have a webpage with two radiobuttons and a dropdownlist as follows:

<div class="sectionheader">Course
    <div class="dropdown"><%=Html.DropDownList("CourseSelection", Model.CourseList, new { @class = "dropdown" })%> </div>         
    <div class="radiobuttons"><label><%=Html.RadioButton("CourseType", "Advanced", false )%> Advanced </label></div>
    <div class="radiobuttons"><label><%=Html.RadioButton("CourseType", "Beginner", true )%> Beginner </label></div>
</div>

The dropdownlist is strongly typed and populated with Model.CourseList (NB – on the first page load, ‘Beginner’ is the default selection and the dropdown shows the beginner course options accordingly)

What I want to be able to do is to update the DropDownList based on which radiobutton is selected i.e. if ‘Advanced’ selected then show one list of course options in dropdown, and if ‘Beginner’ selected then show another list of courses.

Edit – posted my own answer below to show solution that worked for me (finally!)

  • 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-15T03:40:10+00:00Added an answer on May 15, 2026 at 3:40 am

    The code I would like to call sits within my Controller:

    public ActionResult UpdateDropDown(string courseType)
        {
            IDropDownList dropdownlistRepository = new DropDownListRepository();
            IEnumerable<SelectListItem> courseList = dropdownlistRepository.GetCourseList(courseType);
            return Json(courseList);
        }
    

    Using examples provided in jQuery in Action, I now have the following jQuery code:

    $('.radiobuttons input:radio').click(function() 
    {
        var courseType = $(this).val(); //Get selected courseType from radiobutton
        var dropdownList = $("#CourseSelection"); //Ref for dropdownlist
        $.post("/ByCourse/UpdateDropDown", { courseType: courseType }, function(data) {
        $(dropdownList).loadSelect(data);
        });
     });
    

    The loadSelect function is taken straight from the book and is as follows:

    (function($) {
        $.fn.emptySelect = function() {
            return this.each(function() {
                if (this.tagName == 'SELECT') this.options.length = 0;
            });
        }
    
    $.fn.loadSelect = function(optionsDataArray) {
        return this.emptySelect().each(function() {
            if (this.tagName == 'SELECT') {
                var selectElement = this;
                $.each(optionsDataArray, function(index, optionData) {
                var option = new Option(optionData.Text, optionData.Value);
    
                    if ($.browser.msie) {
                        selectElement.add(option);
                    }
                    else {
                        selectElement.add(option, null);
                    }
                });
            }
        });
    }
    })(jQuery);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my webpage I have two dropdown controls for namely ddlmonth and ddldays (
I have a webpage where there are two buttons and a textbox. When the
The two images in the right-hand column of a webpage have been vertically stretched
i have a basic two column webpage i did with css. it includes a
I have a webpage with two side by side overflowing divs that split the
I have a current webpage that is broken into two sections. The top section
I have a webpage having two user control uc1 and uc2. When user clicks
I have a webpage that looks like: <html> <head> <title>Hi</title> </head> <body> <form name=mainForm
I have a webpage where Firefox 2 displays the font certain, really specific elements,
I have a webpage that pulls information from a database, converts it to .csv

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.