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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:58:36+00:00 2026-06-18T12:58:36+00:00

I want to bind the value of a button to my blank viewmodel, how

  • 0

I want to bind the value of a button to my blank viewmodel, how would i do it? I made this fiddle to demonstrate what I ham trying to achieve.

Here is my Viewmodel:

var CustomerSearchViewModel = {
    SearchType: ko.observable(""),
    SearchString: ko.observable("");
}

$(document).ready(function () {
    ko.applyBindings(CustomerSearchViewModel);
});

Here is how I am trying to do the data-bind:

<button type="button" data-bind='value: SearchType, valueUpdate: "afterkeydown"' value="0" class="btn" data-toggle="button">Company Name</button>
  • 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-18T12:58:37+00:00Added an answer on June 18, 2026 at 12:58 pm

    There are multiple ways to solve this but the way how you try to use the value binding with the buttons won’t work.

    One of the easiest solutions which requires the least modification in your HTML is to use the click binding and set the SearchType in the event handler:

    var CustomerSearchViewModel = {
           SearchType: ko.observable(""),
           SearchString: ko.observable(""),
           setSearchType : function(data, element)
           {           
               this.SearchType($(element.target).val());
           }
       };
    

    Then your buttons should look like this:

    <button type="button" data-bind='click: setSearchType'
            value="0" class="btn" data-toggle="button">Company Name</button>
    

    Demo JSFiddle.

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

Sidebar

Related Questions

I am trying to bind enabled property of my button to the maximum value
I want to bind a button's width to some textbox's text value, although I
I want to bind a string value to a text box but only if
I want to bind to a value in a dictionary property of an object.
I want to bind one property to multiple sources. My reason for this are
I want to bind string property with Button.Content. But why it didn't work? The
I have this code: <ribbon:Button Label=Hello /> I wanted to bind its tooltip to
I want to assign property value on button click in aspx page and want
I want to implement that when a textbox value is changed, my Add button
I am trying to bind a group of radio buttons to a value from

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.