Forms are important parts of many web applications. In this section, we will learn about a number of data bindings to work with the form fields:
The
value
bindingThe
click
bindingThe
submit
bindingThe
event
bindingThe
checked
bindingThe
enable
bingingThe
disable
bindingThe
options
bindingThe
selectedOptions
binding
Very often, forms use the input
, select
and textarea
elements to enter text. Knockout.js allows work with such text via the value
binding, as shown in the following example (PersonalPage-Binding-Value.html
):
The Model will be as follows:
var person = { firstName: "John" };
The ViewModel will be as follows:
var PersonViewModel = function() { var self = this; self.firstName = ko.observable(person.firstName); };
The View will be as follows:
<form> The first name is <input type="text" data-bind="value: firstName" />. </form>
The value
property of the text input
element binds to the firstName
property of the ViewModel.