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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:00:02+00:00 2026-06-07T10:00:02+00:00

Question about JS Knockout library – I have three inputs, all data-Bind-ed to the

  • 0

Question about JS Knockout library – I have three inputs, all data-Bind-ed to the same variable. Two have a boolean value of false and one has a boolean value of true. (I can’t change them to ints, unfortunately, which would make this problem easier). Although the two false-valued inputs share behavior, I need to differentiate between them somehow to trigger slightly different behaviors.

Is it possible to data-bind each to another variable, with different values? So instead of each being

    <input data-Bind="checked:test" value="false">

I would have something like

    <input data-Bind="test, test2" value="false, 1">

and

    <input data-Bind="test, test2" value="false, 2">?

I tried that directly and didn’t work so I don’t know if it’s possible. Thanks so much.

  • 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-07T10:00:04+00:00Added an answer on June 7, 2026 at 10:00 am

    You cant bind multiple variables directly but creating a custom bind function do the trick for you.

    Example : http://jsfiddle.net/gurkavcu/ePW8Y/
    ** Change input value (true , false) to trigger the update function

    HTML

    <input data-bind="customData: test , v1 : test2"/>
    <div>
        <span data-bind ="text : test"/>
    </div>
    <div>
        <span data-bind ="text : test2"/>
    </div>
    

    JS

    ko.bindingHandlers.customData = {
          init: function(element, valueAccessor, allBindingsAccessor, viewModel) {  
               $(element).change(function () {
                    valueAccessor()(element.value);
                });       
          },
           update: function(element, valueAccessor, allBindingsAccessor, viewModel) {
              var value =ko.utils.unwrapObservable(valueAccessor());
              var v1 = allBindingsAccessor().v1;
    
              if(value === "true") {
                 v1("1"); 
                 console.log(v1());
              }
              else  if(value === "false") {
                 v1("2"); 
                 console.log(v1());
              }
         }
    };  
    
    
    function ViewModel() {
    
        this.test =  ko.observable(false);
        this.test2 =  ko.observable("2");
    
    };
    
    $(function() {  
    
        var viewModel = new ViewModel();
        ko.applyBindings(viewModel); 
    
    })​
    

    Modify the update function for your needs. You can add any number of variable to the binding with v1 : … , v2 : … , v3 : … and access it via allBindingsAccessor().v1 , allBindingsAccessor().v2 , allBindingsAccessor().v3

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

Sidebar

Related Questions

Question about threading to satisfy my curiosity... Let's say I have static variable _status
Question about OO design. Suppose I have a base object vehicle. And two descendants:
Question about says it all, the server I'm working with doesn't have and smtp
Quick question about data joining. Say I have some elements that each contain a
Note: this question has nothing to do with Knockout.js, but it's about the selectedOptions
Question about GridView sorting in VB.NET: I have a GridView with AutoGenerateColumns = True
simple question about intent action naming convention: I have a new service that handles
A question about symfony form validators. For example I have an url field. If
Quick question about cursors (in particular Oracle cursors). Let's say I have a table
A question about filling an OleDbDataAdapter . I have: Dim cmd As OleDbCommand =

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.