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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:41:14+00:00 2026-06-11T14:41:14+00:00

Is it possible to set the value of a Select Option equal to a

  • 0

Is it possible to set the value of a Select Option equal to a predefined variable, then use its method? Here’s an example:

<select class='hidden' id='teamChoice' onchange='chooseTeam()'>
<option value="" selected>What team</option>
    <option value='bostonCeltics'>Boston Celtics</option>
</select>


var bostonCeltics = {
    conferencePA: "5=Conference=Eastern",
    divisionPA: "5=Division=Atlantic"
}

function chooseTeam() {
    switch ($('teamChoice').selectedIndex) {
        case 0:
            break;
        case 1:
            $('PAType=Name=Value3').innerHTML = this.conferencePA;
            break;
    }
}

Ideally, on selecting the option titled Boston Celtics, I could use a method to access the different properties of the variable object bostonCeltics. Is this possible?

  • 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-11T14:41:15+00:00Added an answer on June 11, 2026 at 2:41 pm

    I’m not a Mootools user, but I think I understand what you’re getting at, and believe I can point you in the right direction.

    In Javascript, you can access any object property directory, OR by using array notation. In other words, given foo = { bar: 1, baz: 2 }, the following are equivalent:

    console.log( foo.bar );      // prints 1
    console.log( foo["bar"] );   // prints 1
    var s = "bar";
    console.log( foo[s] );       // prints 1
    

    Things get trickier because you define bostonCeltics as a var, meaning it’s not necessarily a property of any object. You can still accomplish what you want with eval, though the use of eval is discouraged:

    var s = "bostonCeltics";
    console.log( eval( s + ".conferencePA" ) );    // prints "5=Conference=Eastern"
    

    Personally, I would move bostonCeltics into a parent object, and use the array notation to access its properties, then what you want to do is pretty straightforward. To wit:

    var teams = {
        bostonCeltics = {
            conferencePA: "5=Conference=Eastern",
            divisionPA: "5=Division=Atlantic"
        }       
        // more teams go here
    }
    
    function chooseTeam() {
        var tc = $('teamChoice');
        var val = tc[tc.selectedIndex].value;
        console.log( teams[val].conferencePA );    // prints "5=Conference=Eastern"
    }
    

    Here’s a jsFiddle of this in action: http://jsfiddle.net/sQvBZ/

    I hope this gets to the heart of what you’re asking.

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

Sidebar

Related Questions

I have this Code For example: <select > <option value=volvo>Volvo</option> <option value=saab>Saab</option> <option value=mercedes>Mercedes</option>
<select class=FunctieSelect> <option class=yellow value=-1>- kies -</option> <option class=yellow value=1>KSZ functie</option> <option class=yellow value=2>Bakker</option>
Here is a form element I have. <select id=state name=state style=width: 212px;> <option value=nsw>New
Possible Duplicate: How do I programatically set the value of a select box element
Is it possible to set the value behind a two-way binding directly, without knowing
Is it possible to set the value of an auto-increment field? If a record
is it possible to set a specific Value for the cookie, before fetching a
Is it possible to set one object's key $thumbnailContainer to the value of another
Is it possible to write similar construction? I want to set, somehow, default value
Possible Duplicate: Set Locale programatically I would like to create an english/spanish option choice

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.