Showing posts with label Knockout. Show all posts
Showing posts with label Knockout. Show all posts

Tuesday, September 1, 2015

How to set Knockout Radio Button with a Default Value

If you want to set default value for radio button checked, you need to use an observable attribute with variable values, and each one is a real value for one radio button.

within  data-bind = "checked: TransferType"

TransferType: ko.ovservible("room")  <== Init value

for radiobutton's onchange() event, within the c# code:

ViewModel.TransferType("floating");

Knockout Binding

Textbox Binding

<input type="text" id ="txtFirstName" data-bind="value: Employee.FirstName"/>

Textbox Binding

<input type="radio" id="rdoMale" data-bind="checked: Employee.Gender" name="gender" value="0" />

<input type="radio" id="rdoMale" data-bind="checked: Employee.Gender" name="gender" value="1" />