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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:32:12+00:00 2026-05-30T05:32:12+00:00

I am attempting to set an option in a dropdown/select. I have done this

  • 0

I am attempting to set an option in a dropdown/select. I have done this before, but for some reason I am getting an error and I am not sure why.

Code

var _loc = {
        ALL_BUYS: [{ Text: "All Buys", Value: "AAA"}],
        NETWORK_BREAK: [{ Text: "Network Break", Value: "NTN"}],
        SYNDICATED_BREAK: [{ Text: "Syndicated Break", Value: "STA"}],
        LOCAL_BREAK: [{ Text: "Local Break", Value: "LTA"}],
        NATIONAL_LOCAL: [{ Text: "National/Local", Value: "LTN"}],
        LOCAL_LOCAL: [{ Text: "Local/Local", Value: "LTL"}]//,
    };

lstOptions = $("<select></select>");

$.each(_loc, function (i, item)
    {
        $("<option></option>")
            .appendTo(lstOptions)
            .html(item.Text)
            .val(item.Value) // receive error: Object  has no method 'val'
        });
  • 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-30T05:32:13+00:00Added an answer on May 30, 2026 at 5:32 am

    You’re not grabbing the values from the object correctly.

    The format is like so:

    {key1:[{0, 1}], key2:[{0, 1}], key3:[{0, 1}]}
    

    When you use $.each, it selects each one in this state:

    [{0, 1}]
    

    On the first iteration, it would select the value associated with key1, on the second, key2, etc.

    Since you have arrays nested in each key’s value, you need to specify that it locate the first array in the matched value:

    var _loc = {
        ALL_BUYS: [{ Text: "All Buys", Value: "AAA"}],
        NETWORK_BREAK: [{ Text: "Network Break", Value: "NTN"}],
        SYNDICATED_BREAK: [{ Text: "Syndicated Break", Value: "STA"}],
        LOCAL_BREAK: [{ Text: "Local Break", Value: "LTA"}],
        NATIONAL_LOCAL: [{ Text: "National/Local", Value: "LTN"}],
        LOCAL_LOCAL: [{ Text: "Local/Local", Value: "LTL"}]
    };
    
    lstOptions = $("select");
    
    $.each(_loc, function(i, item){
        $("<option></option>")
            .appendTo(lstOptions)
            .html(item[0].Text)
            .attr("value", item[0].Value);
    });​
    

    Demo.

    Note the item[0]. What this does is select the array with the index 0 in the value that it grabbed. Since there is only one, that single array’s index is 0, so it’s selecting that specific one. Then you find and set its text and value.

    Also note that I changed val() to attr(), because option elements don’t support val() (you could, however, use it on a select element to set the option whose value is equal to the one specified in this function to make it selected).

    TIP: You could also get rid of the literal array indicators around each nested object and use the original method. Demo.

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

Sidebar

Related Questions

I'm attempting to provide a border for a select tag and have been pulling
I have a widget which changes when an option is toggled. This invalidates all
I have this script that I had help with already, but now comes an
Following the instructions in this helpful guide , I've been attempting to set up
I am experiencing an error in a subroutine attempting to set the plotarea.width property
Attempting to set up an automated texting service for customers, where people can text
I'm attempting to set up Pinned Site features for my project. The trouble is
I'm attempting to set up the Laravel PHP Framework to work with Nginx .
I am attempting to set up my own project using a third party library
I am new to all things maven and ignition. I am attempting to set

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.