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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.