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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:57:50+00:00 2026-06-15T23:57:50+00:00

I got a problem with a multiple ViewModel in Knockout.js. The binding works, but

  • 0

I got a problem with a multiple ViewModel in Knockout.js.
The binding works, but when the message box appears which should display the text of the user observable it always writes “undefined”.

Anyone knows hat my problem is?

<!-- ko template: { 'if': loginVM, data: loginVM } -->
    <h3>This is the login</h3>

    User <input type="value: user" type="text"><br/>
    Password <input type="value: password" type="text"><br/>
    <button data-bind="click: showDetails">Show Details</button>
<!-- /ko -->

<!-- ko template: { 'if': detailsVM, data: detailsVM } -->
    <h1>These are the details</h1>
    <button data-bind="click: showLogin">Show Login</button>
<!-- /ko -->

    var masterViewModel = {
        loginVM: ko.observable(),
        detailsVM: ko.observable()
    };

    var LoginVM = function () {
        this.user=ko.observable();
        this.password= ko.observable();
        this.showDetails = function () {
            alert(this.user());
            if(this.user() == "Gregor")
            {
                 masterViewModel.loginVM(null);
                 masterViewModel.detailsVM(new DetailsVM());
            }

        };
    };

    var DetailsVM = function () {
        this.showLogin = function () {
            masterViewModel.loginVM(new LoginVM());
            masterViewModel.detailsVM(null);
        };
    };

    masterViewModel.loginVM(new LoginVM()); 

    ko.applyBindings(masterViewModel);​

Here also is a js.fiddle:
http://jsfiddle.net/4A87x/1/

  • 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-15T23:57:51+00:00Added an answer on June 15, 2026 at 11:57 pm

    You have a typo in the bindings. Should be:

    User <input data-bind="value: user" type="text"><br/>
    Password <input data-bind="value: password" type="text"><br/>
    

    Working fiddle:

    http://jsfiddle.net/4A87x/3/

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

Sidebar

Related Questions

I've got the following problem: I'm trying to highlight text in multiple EditText controls
I've got the following theoretical problem. I'd like to be able to create multiple
Previously, I have worked on local notifications, but I got problem in it now.
I've got a problem with multiple deadlocks on SQL server 2005. This one is
I've got this nasty problem where sending multiple, large messages in quick succession from
I've got a bit of a jQuery problem. I've got multiple tables on a
I've got problem with this peace of code, it should change lower case letters
I'got a problem with compiling linking of a program with multiple files by g++
I've got a little problem. I have multiple relative positioned DIVs in an absolute
I'm trying to save multiple models but have problem with the dropdownlist of the

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.