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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:11:39+00:00 2026-06-13T20:11:39+00:00

I am creating an select like this: <select id=teamNameLabel data-corners=false onchange=GetSelectedTeam() data-bind=options: teams, optionsText:

  • 0

I am creating an select like this:

<select id="teamNameLabel" data-corners="false" onchange="GetSelectedTeam()" data-bind="options: teams, optionsText: 'name', optionsValue: 'id'">
    <option value="1">Select a Team...</option>
</select>

My application is a single page, so when an option is selected it is assigned to TeamId like this:

TeamId = $('#teamNameLabel').val();

I would like the selected option to be what was last selected when you navigate back to this page. I tested it with this when the page loaded, but the alert keeps coming back as undefined.

$("#teamNamelabel option").eq(TeamId+1).attr("selected","selected");
alert($("teamNameLabel option:selected").val());

Is there anyway i can set the selectedOption or .attr(selected) to be TeamId?

  • 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-13T20:11:40+00:00Added an answer on June 13, 2026 at 8:11 pm

    You are missing # in that selector inside your alert and also you can just

    alert($("#teamNameLabel").val());
    

    instead of

    alert($("#teamNameLabel option:selected").val());
    

    And to set the value.. simply use .val again like below,

    $("#teamNameLabel").val(TeamId);
    

    You can use .eq selector when you need to select an option without knowing its value.

    Assume you want to select 3rd option, then

    //             3rd option = 2 because .eq takes index
    $("#teamNamelabel option").eq(2).prop("selected", true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a markup like this <select name=country class=country> <option selected=selected>--Select Country--</option> <option
I was creating a form like this : if select b, the textbox is
I am creating files with xp_cmdshell like this: SELECT @command = 'echo ' +
Is there a way of creating an age select list like this: <?php $Array
I am creating forms elements like this: $element = $this->CreateElement('select', 'countries'); $element->setLabel('Countries'); $element->setAttrib( 'required',
I am creating multiple select element like this and it is showed successfully on
I am creating a select box for a form using this in _form.html.erb <%=
I am creating a temp table with a query like this: CREATE TEMPORARY TABLE
I dream of creating a control which works something like this: <asp:SqlDataSource id=dsFoo runat=server
I have some data which I am binding to a dropdown dynamically like this:

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.