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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:53:46+00:00 2026-06-15T04:53:46+00:00

I am able to populate my select list boxes per guidance from http://learn.knockoutjs.com/#/?tutorial=collections .

  • 0

I am able to populate my select list boxes per guidance from http://learn.knockoutjs.com/#/?tutorial=collections. I am however faced with two problems.

  • The selected index is offset by 1
  • My years select list won’t select any index.

I put a fiddle up here: http://jsfiddle.net/poundingCode/a9MGk/ and added the data from the call to my server.

The thing I find most puzzling is that BDay and BYear controls are virtually identical. The only thing that is different from the underlying Model is that BYear is a nullable datatype, but the value I’m passing in isn’t null.

As always, any guidance would be greatly appreciated.

the code: `var Namespace = {};

    // View model declaration
    Namespace.initMemberVM = function (model) {
        console.log('initViewCalled');
        var memberViewModel = {
            Id: ko.observable(model.Id),
            BDay: ko.observable(model.Days[model.BDay]),
            BMonth: ko.observable(model.Months[model.BMonth]),
            BYear: ko.observable(model.Years[model.BYear]),
            Company: ko.observable(model.Company),
            FName: ko.observable(model.FName),
            LName: ko.observable(model.LName),
            Interests: ko.observable(model.Interests),
            Married: ko.observable(model.Married),
            MName: ko.observable(model.MName),
            Name: ko.observable(model.Name),
            SalutationId: ko.observable(model.SalutationId),
            Salutation: ko.observable(model.Salutations[model.SalutationId]),
            Months: ko.observableArray(model.Months),
            Days: ko.observableArray(model.Days),
            Years: ko.observableArray(model.Years),
            Salutations: ko.observableArray(model.Salutations)
        };
        return memberViewModel;
    };

var data = {“Salutations”:[{“Id”:1,”Name”:”Mr”},{“Id”:2,”Name”:”Mrs.”},{“Id”:3,”Name”:”Ms”},{“Id”:4,”Name”:”Miss”}],”Days”:[{“Id”:”1″},{“Id”:”2″},{“Id”:”3″},{“Id”:”4″},{“Id”:”5″},{“Id”:”6″},{“Id”:”7″},{“Id”:”8″},{“Id”:”9″},{“Id”:”10″},{“Id”:”11″},{“Id”:”12″},{“Id”:”13″},{“Id”:”14″},{“Id”:”15″},{“Id”:”16″},{“Id”:”17″},{“Id”:”18″},{“Id”:”19″},{“Id”:”20″},{“Id”:”21″},{“Id”:”22″},{“Id”:”23″},{“Id”:”24″},{“Id”:”25″},{“Id”:”26″},{“Id”:”27″},{“Id”:”28″}],”Months”:[{“Id”:1,”Name”:”January”},{“Id”:2,”Name”:”February”},{“Id”:3,”Name”:”March”},{“Id”:4,”Name”:”April”},{“Id”:5,”Name”:”May”},{“Id”:6,”Name”:”June”},{“Id”:7,”Name”:”July”},{“Id”:8,”Name”:”August”},{“Id”:9,”Name”:”September”},{“Id”:10,”Name”:”October”},{“Id”:11,”Name”:”November”},{“Id”:12,”Name”:”December”}],”Years”:[{“Id”:”1942″},{“Id”:”1943″},{“Id”:”1944″},{“Id”:”1945″},{“Id”:”1946″},{“Id”:”1947″},{“Id”:”1948″},{“Id”:”1949″},{“Id”:”1950″},{“Id”:”1951″},{“Id”:”1952″},{“Id”:”1953″},{“Id”:”1954″},{“Id”:”1955″},{“Id”:”1956″},{“Id”:”1957″},{“Id”:”1958″},{“Id”:”1959″},{“Id”:”1960″},{“Id”:”1961″},{“Id”:”1962″},{“Id”:”1963″},{“Id”:”1964″},{“Id”:”1965″},{“Id”:”1966″},{“Id”:”1967″},{“Id”:”1968″},{“Id”:”1969″},{“Id”:”1970″},{“Id”:”1971″},{“Id”:”1972″},{“Id”:”1973″},{“Id”:”1974″},{“Id”:”1975″},{“Id”:”1976″},{“Id”:”1977″},{“Id”:”1978″},{“Id”:”1979″},{“Id”:”1980″},{“Id”:”1981″},{“Id”:”1982″},{“Id”:”1983″},{“Id”:”1984″},{“Id”:”1985″},{“Id”:”1986″},{“Id”:”1987″},{“Id”:”1988″},{“Id”:”1989″},{“Id”:”1990″},{“Id”:”1991″},{“Id”:”1992″},{“Id”:”1993″}],”Associations”:””,”BDay”:2,”BMonth”:2,”BYear”:1983, “SalutationId”:1, “FName”:”James”, “MName”:”R”, “LName”:”Fleming”, “Interests”:”What I’d like to know is WHY won’t the year select dropdown show the value 1983??? AND WHY is it that the selected Index is off by 1? SalutationId = 1 but the value displayed is for SalutationId #2…”};

    $(document).ready(function () {
          var viewModel = Namespace.initMemberVM(data);
        ko.applyBindings(viewModel);
    });`

the HTML

<article>
    <h2>Summary</h2>
    <label data-bind="text: FName"></label>
    <table>
        <tbody>
        <tr><td>User Id</td><td colspan="4"><label data-bind="text: Name"></label></td></tr>
        <tr>
        <td>Salutation</td><td><select data-bind="options: Salutations, value: Salutation, optionsText: 'Name', optionsCaption: 'Select'"></select></td>
        </tr>
        <tr>
        <td></td><td>First</td><td>Middle</td><td>Last</td>
        </tr>
        <tr>
            <td>Name</td><td><input type="text" data-bind="value: FName"></td><td><input type="text"  data-bind="value: MName"></td><td><input type="text"  data-bind="value: LName"></td>
        </tr>
        <tr><td></td><td colspan="2">Month &nbsp;&nbsp; Day &nbsp;&nbsp; Year</td></tr>
            <tr><td>DOB</td><td colspan="2">
                                <select name="BMonth" data-bind="options: Months, value: BMonth, optionsText: 'Name', optionsCaption: 'Select'"></select>/
                                <select name="BDay"     data-bind="options: Days, value: BDay, optionsText: 'Id',  optionsCaption: 'Select' "></select>
                                <select name="BYear" data-bind="options: Years, value: BYear, optionsText: 'Id', optionsCaption: 'Select'"></select>
                            </td><td> <label><input type="checkbox" data-bind="checked: Married">Married</label></td></tr>
        <tr><td><label>Interests</label></td><td colspan="3"><textarea data-bind="value: Interests" rows="10" cols="40"></textarea></td></tr>
    </tbody>

</article>

  • 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-15T04:53:48+00:00Added an answer on June 15, 2026 at 4:53 am

    I got it – see previously mentioned fiddle for answer. What I needed to do was two things to make the values appear as expected. I fell in a hole for longer than I’d care to admit, but I hope this lesson learned can help someone else.

    I had to send in the Id not the object

                BDay: ko.observable(model.BDay),
                BMonth: ko.observable(model.BMonth),
                BYear: ko.observable(model.BYear),
    

    vs

    BDay: ko.observable(model.Days[model.BDay]),
    BMonth: ko.observable(model.Months[model.BMonth]),
    BYear: ko.observable(model.Years[model.BYear]),
    Company: ko.observable(model.Company),

    I also needed to update the HTML of the selects by adding optionsValue: ‘Id’.

    Hope this helps

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

Sidebar

Related Questions

I want to define a class that is able to populate itself reading from
I am creating a SelectList from a List(T) class to use to populate a
Im able to populate my formset with the elements of an array which is
I recently have just been able to populate my core data DB. I have
Not able to download artifacts from central maven repository. <mirrors> <!-- mirror | Specifies
not able to get this, can someone help for this LINQ query? select col1,
I need to be able to access a list throughout my Rails project. For
I have a table layout that I want to populate with the result from
Would like to be able to populate any properties of an object and search
i am unable to populate my Struts2 select drop down in my jsp page.

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.