Form fields bindings

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 binding
  • The click binding
  • The submit binding
  • The event binding
  • The checked binding
  • The enable binging
  • The disable binding
  • The options binding
  • The selectedOptions binding

The value 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); ...

Get Getting Started with Knockout.js for .NET Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.