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 3281576
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:49:51+00:00 2026-05-17T19:49:51+00:00

I found this solution on here How to update strongly typed Html.DropDownList using Jquery

  • 0

I found this solution on here How to update strongly typed Html.DropDownList using Jquery and am trying to implement it, but something is bugged in it.

$(function() {
    $('#cid').change(function() {
        var selectedCompany = $(this).val();
        var ddl = $("#foid");
        $.post("/TimeTracking/FilterFieldOffices", { companyId: selectedCompany }, function (data) {
            $(ddl).loadSelect(data);
        });
    });
});

(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);

My controller returns a select list of what i want.

public ActionResult FilterFieldOffices(int companyId = 0)
    {
        IList<FieldOffice> list = _fodp.GetFieldOfficesForCompany(companyId);

        var returnList = new SelectList(list, "Id", "FacilityName");

        return Json(returnList);
    }

I know the .change function is firing by placing alerts, and i know that my controller function is being called through breakpoints, so that narrows it down to the loadselect function, however i cant narrow it down anymore, since no alerts will fire within the load select function. I dont have enough experience with JQuery to form an opinion on whats wrong. So im asking if anyone has had any success on what im trying to do, or if you can see something wrong with the code.
And before anyone asks, yes i have checked the brackets.

edit Forgot to mention that i checked the error console for firefox and i get the error:

$(ddl).loadSelect is not a function.

edit Found a resource that mentions that the error i described arises when you have two conflicting frameworks. So i put in jQuery.noConflict(); and it still does not work.

  • 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-17T19:49:51+00:00Added an answer on May 17, 2026 at 7:49 pm

    Very bizzare, but i came up with a solution that i can break point through.

    <script type="text/javascript">
    
            $(function () {
                $('#cid').change(function () {
                    var coid = $(this).val();
                    $.post("/TimeTracking/FilterFieldOffices", { companyId: coid }, function (data) {
                        $("#foid").loadSelect(data); 
                    });
                });
            });
    
            $(function () {
                $.fn.loadSelect = function (data) {
                    return this.each(function () {
                        this.options.length = 0;
                        $.each(data, function (index, itemData) {
                            var option = new Option(itemData.Text, itemData.Value);
                            this.add(option);
                        });
                    });
                };
            });
    
        </script>
    

    All i had to do was to wrap the function that wasnt being called in a $(function() { //Code here });
    However im still having some trouble. I made a new page for it.

    Refreshing a dropdownlist after elements have been reset

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

Sidebar

Related Questions

I found this solution which works, but I find it hard to believe there
problem euler #5 i found the solution but i don't know why this first
This is something I've pseudo-solved many times and have never quite found a solution
Update: A sample project reproducing this bug can be found here at Microsoft Connect
Good day! I've found this solution here: VS2010 Web Publish command line version of
I frequently run into problems of this form and haven't found a good solution
I found this link http://artis.imag.fr/~Xavier.Decoret/resources/glsl-mode/ , but there isn't a lot of description around
I found this in an article on Multithreaded Apartments, but can’t find a definition
I found this guide for using the flash parameters, thought it might be useful
UPDATE: I found a solution. See my Answer below. My Question How can I

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.