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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:48:16+00:00 2026-06-04T22:48:16+00:00

I am trying to write a bit of UI that allows the user to

  • 0

I am trying to write a bit of UI that allows the user to either enter a number via a textbox or pick an option from a drop down.

I have made a simplified jsFiddle at http://jsfiddle.net/unklefolk/PNQeR/2/

As you can see:

  • When “The number” is selected you can enter a text into a textbox.
  • When “The option” is selected you can select one of two options from a drop down

The textbox and the drop down are BOTH bound to the ItemValue property of item in the viewModel. Although the code seems to be working I am getting errors. If you fire up the debug window in Chrome, when you change the first drop down you get the error:

Uncaught TypeError: Object 0 has no method ‘ItemName’

I believe this is happening in the ItemText dependentObservable (aka computed).

    this.ItemText = ko.dependentObservable(function () {
        return _isItemAConstant() === 'true' ? this.ItemValue() : this.ItemValue().ItemName();
    }, this);

Clearly the ItemName() function is being called on the numeric value ‘0’ causing the error.

What can I do so that this error does not occur? Is my design of binding two controls to the same observable a fundamental error?

  • 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-04T22:48:18+00:00Added an answer on June 4, 2026 at 10:48 pm

    You change _isItemAConstant to false before setting the item to an object that has the ItemName property. As soon as you set it, your dependentObservable gets run and tries to evaluate the ItemName() observable which doesn’t exist. You can either check for the existence of the ItemName property or use the throttle extender to delay computation until all changes are made:

    this.ItemText = ko.dependentObservable(function () {
        return _isItemAConstant() === 'true' ? this.ItemValue() : this.ItemValue().ItemName();
    }, this).extend( { throttle: 1} );
    
    this.ItemText2 = ko.computed(function() {
        return this.ItemValue().ItemName ? this.ItemValue().ItemName() : this.ItemValue();
    }, this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying so write a bit of code that will search for a
I'm trying to write a bit of SQL for SQLITE that will take a
I'm trying to write a shader that uses many bit operations. In fact they
I'm trying to write something that will allow a user to use a keyboard/mouse
I am trying to write one portion of my huge C# program that allows
I'm trying to write an application that converts 48 bit-per-pixel PNG files to a
I'm trying to write an algorithm for a number theory/computer science merged class that
I am trying to write a macro in Clojure that allows for evaluation of
I'm trying to write a query that will set a bit value, based on
I am trying to write unit tests for a bit of code involving Events.

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.