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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:41:37+00:00 2026-06-15T07:41:37+00:00

In html, when we click on the text or hover over the text of

  • 0

In html, when we click on the text or hover over the text of a radio button or checkbox, we are able to select it with the html as shown below:

<label>
<input type="checkbox" />option 1
</label>

OR

<input id="checkboxid" type="checkbox" />
<label for="checkboxid">option 1</label>

I am trying to get the same behavior with knockout, but unable to find much help on the same:

<label data-bind="text: $data.optiontext">
    <input type="checkbox" data-bind="value: $data.optionvalue, checked: $parent.selectedOptions" />
</label>

The View (or html) is below (Note the below code does not contain the above html, so when you try it you will need to make the above changes and check it):

<div data-bind="foreach: options">
    <input type="checkbox" data-bind="value: $data.optionvalue, checked: $parent.selectedOptions" />
    <label data-bind="text: $data.optiontext"></label>
</div>

<hr />

<div data-bind="text: selectedOptionsList"></div>​

Here is the view model:

var viewModel = {
    options: [
                { optiontext: 'Simple', optionvalue: "1" },
                { optiontext: 'Advanced', optionvalue: "2" }
             ],
    selectedOptions: ko.observableArray(["2"])
};

viewModel.selectedOptionsList = ko.computed(function() {
    return this.selectedOptions().join(",");
}, viewModel);

ko.applyBindings(viewModel);

Here is the jsFiddle link: http://jsfiddle.net/rupesh_kokal/AFzbY/

  • 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-15T07:41:38+00:00Added an answer on June 15, 2026 at 7:41 am

    You can achieve the 1. version with using an extra span for the text:

    <label>
        <input type="checkbox" data-bind="value: $data.optionvalue, 
               checked: $parent.selectedOptions" />
        <span data-bind="text: $data.optiontext"/>
    </label>
    

    Demo fiddle.

    Or the 2. version with using the attr binding to set the id and the for attribute:

    <input type="checkbox" data-bind="value: $data.optionvalue, 
           checked: $parent.selectedOptions, attr: { id: optiontext}" />    
    <label data-bind="text: $data.optiontext, attr: {for: optiontext}" />
    

    Demo fiddle

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

Sidebar

Related Questions

I saw How to hide html source & disable right click and text copy?
My code is: $(document).ready(function(){ //alert('hi'); $('#call1').click(function(){ $.('#text').load('click1.html') }) $('#call2').click(function(){ $.('#text').load('click2.html') }) $('#call3').click(function(){ $.('#text').load('click3.html') })
<script type='text/javascript'> $(document).ready(function() { $(#specific_consultant_yes).click(function() { $('.specific').show('slow'); $.post(<?php echo $this->url(array('controller'=>'appointment', 'action' =>'available'),'default',true)?>,{app_date:$(#App_date).val(),consultant:$(#Consultants).val()} ,function(data){ $(.new).html(data);
I have a HTML page on click of button i am displaying a Popup
I want to call a html page on click of a button in mvc.
Project: http://design.vitalbmx.com/fave/news.html When I click Add to favorites button (under main pic), in Chrome
How to disable asp:TextBox on client-side click on HTML checkbox or server-side asp:CheckBox using
Here's my code: <!doctype html> <html> <head> <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script> <style type=text/css> label {display:block;
My HTML: <!DOCTYPE html> <html> <head> <style type=text/css> /* Make all anchors and variations
<input type=text id=sShState /> $('#sShState').liveSearch(); // A plug-in // inside plug-in: $this = $(this);

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.