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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:18:10+00:00 2026-06-10T17:18:10+00:00

One of my radio should selected when initialize (first load then user can change

  • 0

One of my radio should selected when initialize (first load then user can change the selection), but radio is not selected first time, how to initialize “Selected” appropriately?

Here radio “Two” should selected as “selected” is True for this?

@using (Html.BeginForm("Index", "Two", FormMethod.Post, new Dictionary<string, object> { { "data-bind", "submit:onSubmit" } }))
{

<table>
    <tr>
        <td>
            <div data-bind="foreach: items">
                <input type="radio" name="items" data-bind="attr: { value: id }, checked: $root.selected" />
                <span data-bind="text: name"></span>
            </div>
            <div data-bind="text: selected">
            </div>
        </td>
    </tr>
</table>

<input type="submit" name="send" value="Send" />
}

<script type="text/javascript">
var viewModel = {
    items: [
    { "id": 1, "name": "one", "selected": false  },
    { "id": 2, "name": "two", "selected": true },
    { "id": 3, "name": "three", "selected": false }
],
selected: ko.observable(),

    onSubmit: function(){

        var x = this.selected();

        }
    };

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

</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-10T17:18:12+00:00Added an answer on June 10, 2026 at 5:18 pm

    You need to set your top level selected observable to the id of the value that is true.

    something like:

    $(function() {
        var selected = ko.utils.arrayFirst(viewModel.items, function(item) {
            return item.selected; 
        });
    
        if (selected) {
           viewModel.selected(selected.id);   
        }
    
        ko.applyBindings(viewModel);
    });
    

    Sample: http://jsfiddle.net/rniemeyer/rbsZC/

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

Sidebar

Related Questions

I want to select only one radio button but I cant do this. Here
How can i disable the one radio input from the radio group ? <input
In a set of radio buttons of the same group, only one can be
the html page contains 3 radio buttons- red,green, blue.If we selected any one of
I have radio buttons in my project which should get disabled if one of
i have 3 radio buttons.what i need to do is that when one radio
Here i got a problem in my script, Once we set one radio button
I have two forms, one with a radio button that users must select to
The form has one or more groups of radio buttons on it. It is
Iam developing one application.In that iam placing the radio buttons(uiimageview) on table view and

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.