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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:20:25+00:00 2026-05-30T22:20:25+00:00

I use the the following ViewModel <script type=’text/javascript’> $(function () { var dropdownCtor =

  • 0

I use the the following ViewModel

<script type='text/javascript'>
$(function () {

    var dropdownCtor = function (text, value, defaultValue) {
        this.text = text;
        this.value = value;
        this.defaultValue = defaultValue;
    };

    var productsViewCtor = function () {

        var self = this;

        this.productType = ko.observable();
        this.productTypes = ko.observableArray(['Summer', 'Winter']);
        this.products = ko.observableArray();
        this.product = ko.observable();

        this.productType.subscribe(function (newProductType) {


            $.post(
        '/Home/GetProducts',
        { productType: newProductType },
        function (resultProducts) {
            self.products(resultProducts);
            self.product(resultProducts[2]);
        });

        } .bind(this));

    }
    var productViewModel = new productsViewCtor();

    ko.applyBindings(productViewModel);

});

An the following Html

<h3> Your Products:</h3>
<p>
     <span><select data-bind="options: productTypes, value: productType"></select></span>
   <span>
   <select data-bind="options: products , optionsText: 'text' ,  optionsValue: 'value' , value: product"></select></span>
</p>
<ol class="round">
 <li >
        <h5   >productType</h5>
       <span data-bind="text: productType"></span>
    </li>
     <li >
        <h5   >product</h5>
       <span data-bind="text: product"></span>
    </li>
</ol>

When the page loads the ajax call is sent and I receive all the products for winter. They are displayed inthe dropdown and the selected value is 101.

By selecting “summer” in the productType dropdown I try to load the producst again. This is also successfull. But then I want to preselect an option (here the 3rd one) by setting a specific product in the VoewModel. This product is not selected in the dropdown and also not displayed inside the span tag.

How can I select an item in the dropdown?

  • 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-30T22:20:27+00:00Added an answer on May 30, 2026 at 10:20 pm

    You specified the optionsValue binding on your product select to be ‘value’. This is the property that will be bound by the value binding to product.

    So you need to do:

    self.product(resultProducts[2].value);
    

    Here is a fiddle where I demonstrate this. The sub options I load are an object, and I have to set my selectedSubOption to the id I want.

    http://jsfiddle.net/jearles/Z7jzr/

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

Sidebar

Related Questions

Please consider the following code (also in this fiddle ): var viewModel = {
I'm trying to use the search text box (which I made by following this
I use the following code to create countdowns in Javascript. n is the number
I use the following for a jQuery link in my <script> tags: http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js Is
Following on from this question , I'm using a simple ViewModel class to test
Good day! I've the following ViewModel class I use for login form: using System.ComponentModel.DataAnnotations;
for example i use following command to find a record SELECT `users`.`mail` FROM `users`
I would like to use following sql to avoid constructing sql dynamically: SELECT CommentID,
I am working on a PHP project. There, I often use following syntax to
I use the following to get a list of project files that need to

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.