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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:14:26+00:00 2026-06-13T01:14:26+00:00

below is my MVC app code with KnockOut JS, I have submit button with

  • 0

below is my MVC app code with KnockOut JS, I have submit button with “onClick” event “SetData()”.

how to get all id of selected checkbox, I put commented code that works inside KnockOut OnSubmit, but I want outside,

///

@model Demo.Web.ViewModels.HomeViewModel
@{
   ViewBag.Title = "Two Page";
 }
@using (Html.BeginForm())
{
<table>
    <tr>
        <td>
            <span data-bind="foreach: pageOptions">
                <input type="checkbox" data-bind="checked: IsChecked" />
                <span data-bind="text: OptionName"></span>
                <br />
            </span>
        </td>
    </tr>
</table>

<input type="submit" name="send" value="Send" onclick="SetData();" />
}

<script type="text/javascript">
var viewModel = {
    pageOptions: ko.observableArray([{"OptionCode":1,"OptionName":"Option 1","IsChecked":true},{"OptionCode":2,"OptionName":"Option 2","IsChecked":false},{"OptionCode":3,"OptionName":"Option 3","IsChecked":true},{"OptionCode":4,"OptionName":"Option 4","IsChecked":true}]),
    IsChecked: ko.observableArray()
    };

$(function() {
        ko.applyBindings(viewModel);
    });


function SetData() {
    alert('f');
    //         var ids = [];
   //                $.each(this.pageOptions(), function(n, item) {
   //                    if(item.IsChecked)
   //                    ids.push(item.OptionCode);
   //                });
   }

  </script>     

///
  • 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-13T01:14:28+00:00Added an answer on June 13, 2026 at 1:14 am

    The

    IsChecked: ko.observableArray()
    

    is never used. Define IsChecked property of the pageOptions elements as an observable():

    var viewModel = {
        pageOptions: ko.observableArray([{"OptionCode":1,"OptionName":"Option 1","IsChecked": ko.observable(true)},{"OptionCode":2,"OptionName":"Option 2","IsChecked": ko.observable(false)},{"OptionCode":3,"OptionName":"Option 3","IsChecked":ko.observable(true)},{"OptionCode":4,"OptionName":"Option 4","IsChecked":ko.observable(true)}]),
        IsChecked: ko.observableArray() ---> delete this, you don't need it
    };
    

    Then, outside the knockout domain you can access the values with:

    for(var i = 0; i < viewModel.pageOptions().length; i++) {
        if(viewModel.pageOptions()[i].IsChecked()) { 
            ---> the logic you want to use 
        }
    }
    

    Knockout update the IsChecked property of the JSON object as long as the checkbox is data-binded with an ko.observable(). If you just data-bind with a value (true/false) the object is never updated when the user check or uncheck the html control.

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

Sidebar

Related Questions

I have an MVC app with a Partial View (below). When I add Html.EnableClientValidation(),
Ok i have an mvc app. and im trying to get my delete to
I'm trying to get an ASP.NET MVC app working... I should have known it
I have an MVC/Nhibernate app that is giving me the below. [WrongClassException: Object with
Below is my Get method of MVC Web Api RC. public Employee Get(int id)
In the MVC View code below, isLoggedInDb is underlined in green with a tooltip
I am new to spring MVC. i have below project structure. Below are classes:
We have an app written in ASP.NET MVC 3, that uses @Html.AntiForgeryToken() . We
I have hosted .NET 4.0 / ASP.NET MVC 3 app on IIS 6 on
i have an asp.net mvc app that has a form that uploads a file.

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.