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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:55:23+00:00 2026-06-01T01:55:23+00:00

I still consider myself quite a novice when it comes to JavaScript/JQuery. How would

  • 0

I still consider myself quite a novice when it comes to JavaScript/JQuery. How would I go about refraction this into a method/function I can re-use.

$.getJSON('@Url.Action("GetLabNames", "Micro")', null, function(j) {
    var options = '';

    for (var i = 0; i < j.length; i++) {
        if (elem.value == j[i].Description) {
            options += '<option selected="selected" value="' + j[i].Lab_LN_ID + '">' + j[i].Description + '</option>'
        } else {
            options += '<option value="' + j[i].Lab_LN_ID + '">' + j[i].Description + '</option>'
        }
    }

    $(elem).html(options);

    $(elem).multiselect({
        multiple: false,
        header: "Select an option",
        noneSelectedText: 'Lab Name',
        selectedList: 1,
        minWidth: 150
    });

});

I was hoping to have a function something like

 CreateMultiSelect(elem, controller, action, text, value);

But I can’t pass object properties into the function eg (Lab_LN_ID , Description), and making them text (eg ‘Lab_LN_ID’, ‘Description’), clearly doesn’t work, and I’m not sure how to go about it?

  • 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-06-01T01:55:24+00:00Added an answer on June 1, 2026 at 1:55 am

    Why not return a json object with common property names? It would simplify this greatly.

    eg

    [{Text: 'text', Value: '1'},{Text: 'text', Value: '1'}]
    

    Then you can create all your option items very easily.

        $('<option />', { value: item.Value, text: item.Text });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I still consider myself a beginner when it comes to JQUERY+Coldfusion...so I'd like to
I still consider myself a novice with javascript...so be gentle :) Is there a
ALthough I've had to dabble in shell scripting and commands, I still consider myself
I'd consider myself a reasonable standard CSS/XHTML chap but I'm pretty baffled by this.
I've been coding for a while, but still consider myself a beginner. I use
I consider myself still pretty new to the TDD scene. But find that no
still trying to find where i would use the yield keyword in a real
Still a bit new to Linq. This is driving me nuts. I want to
Still working through JQuery to get data and repopulate portions of a page. Right
I consider myself a very experienced SQL person. But I'm failing to do these

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.