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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:41:36+00:00 2026-06-13T21:41:36+00:00

I feel like I’m missing something very basic, but I can’t get a dropdown

  • 0

I feel like I’m missing something very basic, but I can’t get a dropdown menu to work as I expect using Knockout.js.

I have a set of objects I want to present in a menu, and I need to find the selected option and post that to the server. I can get the menu to render, but can’t seem to get the value of the selected item. My view model looks like this:

function ProjectFilterItem( name, id ) {
    this.Name = name;
    this.Id   = id;
}

function FilterViewModel() {
    this.projectFilters = ko.observableArray([
        new ProjectFilterItem( "foo", "1" ),
        new ProjectFilterItem( "bar", "2" ),
        new ProjectFilterItem( "baz", "3" )
    ]);
    this.selectedProject = ko.observable();
}

ko.applyBindings( new FilterViewModel() );

and my view markup looks like this:

<select 
    id        = "projectMenu"   
    name      = "projectMenu"
    data-bind = "
        options:        projectFilters,
        optionsText:    'Name', /* I have to enquote the value or I get a JS error */
        optionsValue:   'Id',   /* If I put 'selectedProject here, nothing is echoed in the span below */
        optionsCaption: '-- Select Project --'
    "
></select>

<b>Selected Project:</b> <span data-bind="text: selectedProject"></span>

How do get the selected menu item to display in the span, and to post to the server? (I assume the observable I render in the span is the same one I’d post.) Do I need another property in the ProjectFilterItem, like this.selected = ko.observable(false); ? If so, how would I declare it as the target of the value?

  • 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-13T21:41:38+00:00Added an answer on June 13, 2026 at 9:41 pm

    You just need use with the value binding to bind the selected value:

    From the options documentation:

    Note: For a multi-select list, to set which of the options are
    selected, or to read which of the options are selected, use the
    selectedOptions binding. For a single-select list, you can also read
    and write the selected option using the value binding.

    In your example:

    <select 
        id        = "projectMenu"   
        name      = "projectMenu"
        data-bind = "
            value: selectedProject,
            options:        projectFilters,
            optionsText:    'Name',
            optionsValue:   'Id',
            optionsCaption: '-- Select Project --'
        "
    ></select>
    

    See Demo.

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

Sidebar

Related Questions

I feel like I'm missing something very obvious here, but I can't get a
I feel like I'm missing something obvious, but I can't work out why my
I feel like I am missing something very simple here, but this is the
I feel like this is a very noob question.. but I just can't get
I feel like there's something about grids that I'm missing, but I can't find
I feel like this must be very easy, but I can't find the answer
I feel like I'm missing something here, but I have this datagrid which when
I feel like I am just missing a simple property, but can you set
I feel like there's something rather basic I'm missing here, which I previously thought
I feel like this must be simple to do but can't get it done

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.