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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:08:24+00:00 2026-05-26T20:08:24+00:00

Here is a subset of the markup I am using: <div id=item_one></div> <div id=item_two></div>

  • 0

Here is a subset of the markup I am using:

<div id="item_one"></div>
<div id="item_two"></div>
<div id="item_three"></div>

<p id="result_one">0</p>
<p id="result_two">0</p>
<p id="result_three">0</p>

The desired behaviors are:

  1. When you click a div, the corresponding text of the p tag is toggled from 0 to 1.
  2. The text of the p tags is to be concatenated into a string, e.g., click the second item and the resulting string would be “010”.
  3. There is an array of eight items, with binary strings as the key. As clicks are made, the selected item in the array changes.

This seems like a good use of knockout, but I am a complete noob. How do I set up the proper dependencies?

  • 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-05-26T20:08:25+00:00Added an answer on May 26, 2026 at 8:08 pm

    Here is a sample for one way to do it: http://jsfiddle.net/rniemeyer/XqDsy/

    For convenience, I created a little “binaryObservable” that exposes a toggle function.

    function binaryObservable(initialValue) {
       var result = ko.observable(initialValue);
       result.toggle = function() {
           result(result() === "1" ? "0" : "1");    
       };
       return result;
    }
    
    function ViewModel() {
       this.one = binaryObservable("0");
       this.two = binaryObservable("0");
       this.three = binaryObservable("0"); 
    
       this.combined = ko.dependentObservable(function() {
          return this.one() + this.two() + this.three();       
       }, this);
    
       this.choices = {
            "000": { id: 0, value: "000" },
            "001": { id: 1, value: "001" },
            "010": { id: 2, value: "010" },
            "011": { id: 3, value: "011" },
            "100": { id: 4, value: "100" },
            "101": { id: 5, value: "101" },
            "110": { id: 6, value: "110" },
            "111": { id: 7, value: "111" }
       };
    
       this.selectedChoice = ko.dependentObservable(function() {
           var combined = this.combined();
           return combined ? this.choices[combined] : {};
       }, this);   
    }
    
    ko.applyBindings(new ViewModel());
    

    Then the HTML might look like:

    <div id="item_one" data-bind="click: one.toggle">option one</div>
    <div id="item_two" data-bind="click: two.toggle">option two</div>
    <div id="item_three" data-bind="click: three.toggle">option three</div>
    
    <hr/>
    
    <p id="result_one" data-bind="text: one">0</p>
    <p id="result_two" data-bind="text: two">0</p>
    <p id="result_three" data-bind="text: three">0</p>
    
    <hr/>
    
    <p data-bind="text: combined"></p>
    
    <hr/>
    
    Selected choice: <span data-bind="text: selectedChoice().id"></span>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to sample a subset from data with replacement and here I
How can i find all subsets of a set using c#? here set is
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Hey guys here is my question. im using JCombobox. if a student have CB
I'm using a modelform to display only a subset of the fields in the
Here is a subset of my tables: orders: - order_id - customer_id order_products: -
I am using a subset to extract from set of a column values I
I want to get a subset of a table, here's the example: 1 A
The question here is – is it possible to import subset of types from
Does anyone know how to use the subset.ff function in the ff package? Here

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.