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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:49:19+00:00 2026-06-18T01:49:19+00:00

I am trying to understand knockout. And there is a thing I don’t understand.

  • 0

I am trying to understand knockout. And there is a thing I don’t understand. We have html:

<p>
<input type='checkbox' data-bind="checked: hasCellphone" />
I have a cellphone</p>

<p>
Your cellphone number:
<input type='text' name='cell' data-bind="value: cellphoneNumber, enable: hasCellphone" /></p>

<button data-bind="enable: document.getElementsByName("cell")[0].value != '555'">
Do something</button>

And JS:

function AppViewModel() {   
this.hasCellphone = ko.observable(false);
this.cellphoneNumber = ko.observable("");}

ko.applyBindings(new AppViewModel());

So, enable for input works, but not for the button, even if I enter ‘555’ into the input it still stays enabled.

  • 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-18T01:49:20+00:00Added an answer on June 18, 2026 at 1:49 am

    The example on the knockout page is a bit misleading. The enable binding takes any value but for automatic updates it must be an observable. document.getElementsByName("cell")[0].value != '555' is not an observable.

    You can fix the code easily by adding a cellphoneNumberValid observable to the model which is based on the value of the cellphoneNumber observable:

    html

    <p>
        <input type='checkbox' data-bind="checked: hasCellphone" />
        I have a cellphone
    </p>
    
    <p>
        Your cellphone number:
        <input type='text' name='cell' data-bind="
                value: cellphoneNumber,
                valueUpdate: 'afterkeydown',
                enable: hasCellphone" />
    </p>
    

    Do something

    js

    function parseAreaCode(s) {
        // just a dummy implementation
        return s.substr(0, 3);
    }
    
    function AppViewModel() {   
        this.hasCellphone = ko.observable(false);
        this.cellphoneNumber = ko.observable("");
        this.cellphoneNumberValid = ko.computed(function() {
            return parseAreaCode(this.cellphoneNumber()) != '555';
        }, this);
    }
    
    ko.applyBindings(new AppViewModel());
    

    jsfiddle

    http://jsfiddle.net/bikeshedder/eL26h/

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

Sidebar

Related Questions

Trying to understand why i don't have to convert null to DBNull when using
I'm trying to understand the knockout syntax and have the following question. If I
I am trying understand ViewModels deeper and I have read many articles and blogs
Trying to understand the filter function of AngularJS most of the examples have the
Trying to understand what Sql Profiler means by emitting sp_reset_connection. I have the following,
trying to understand how custom admin commands work, I have my project named mailing
In trying to understand the correlation between program objects and data in tables (here:
Im trying to understand what a functor is, i found this tutorial/example: http://en.wikibooks.org/wiki/Haskell/Solutions/Applicative_Functors data
trying to understand methods and virtual function lets say i have 3 classes (the
Trying to understand the new async/await pattern, I have one question which I can't

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.