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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:01:19+00:00 2026-06-02T19:01:19+00:00

I have a simple jsfiddle where I’m trying to better understand value binding. I

  • 0

I have a simple jsfiddle where I’m trying to better understand value binding. I have an input control value bound to a search property on my viewModel as follows:

<input data-bind="value: search" />

I have the search property as defined as:

this.search = ko.observable("");

I also have subscribe implemented on the “search” property as follows:

this.search.subscribe(function(newValue) {
    alert("New value is " + newValue);
    alert("New value is" + this.search);
});

I can see newValue change as I type and then select another control, but the viewModel property search does is always undefined. I was expecting with 2-way binding that as I type information search would have the type value so that I could use it say in a button that executes a webservice call using ajax, but undefined is the only value that I can get in the field without setting the default value of the search.

Is it expected that I change the value of search in the subscribe call? I thought this would be done for me by having it 2-way bound.

  • 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-02T19:01:23+00:00Added an answer on June 2, 2026 at 7:01 pm

    Firstly, within the subscribe method, this does not reference the view model and so there is no search property available (hence undefined). You can work around this by saving a reference to the view model under another variable name such as _self and access search using that reference.

    Secondly, you need to call search as a function in order to get it’s value – this is true of all observable values when working with Knockout.

    var viewModel = function() {
        var _self = this;
        this.search = ko.observable("");
    
        this.search.subscribe(function(newValue) {
            alert("New value is " + newValue);
            alert("New value is " + _self.search());
        });
    };
    

    Updated Fiddle

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

Sidebar

Related Questions

I have such simple form in html: <form action=add method=get> <input name=ok type=submit value=ok
I have made a simple table form here in jsfiddle . I also put
I have list of images with some simple mouseenter / mouseleave effect. http://jsfiddle.net/4vTCr/ I
I have a simple script that closes a DIV. An example is here: http://jsfiddle.net/22fTm/3/
I have a simple Handlebars helper which simply formats a money value. The helper
i have this simple code http://jsfiddle.net/U4Fj9/ the index of the visible image is always
I have a simple HTML structure ( jsfiddle ): <li> <div class=buttons> <a href=done><img
i have this simple example here : http://jsfiddle.net/pTyvc/1/ i don't want the sub_menu div
I have a simple div that if clicked to much turns blue: JsFiddle In
I have a simple problem with array, i can't solved. Example : http://jsfiddle.net/8jyUT/ Why

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.