# WinJS Two-Way Bindings

DevFeed: [WinJS Two-Way Bindings](<https://devfeed.tech/articles/winjs-two-way-bindings-41552.md>)

Original publisher: [Read original article](<http://www.adamtuliper.com/2013/06/winjs-two-way-bindings.html>)

Author: Adam Tuliper (noreply@blogger.com)

Published: 2013-06-03T04:24:00Z

Content type: tutorial

Language: en

Sources: [Adam Tuliper](<https://devfeed.tech/sources/adam-tuliper.md>)

Topics: [data](<https://devfeed.tech/topics/data.md>), [input](<https://devfeed.tech/topics/input.md>), [function](<https://devfeed.tech/topics/function.md>)

Tags: [data](<https://devfeed.tech/tags/data.md>), [event](<https://devfeed.tech/tags/event.md>), [function](<https://devfeed.tech/tags/function.md>), [input](<https://devfeed.tech/tags/input.md>), [model](<https://devfeed.tech/tags/model.md>), [source](<https://devfeed.tech/tags/source.md>), [value](<https://devfeed.tech/tags/value.md>)

## AI overview

A tutorial explains how to implement two-way data binding in WinJS by combining one-way binding from source data to a destination with onchange event wiring from an input control back to the source model.

## Source excerpt

I learned a really cool trick from one of my team members Jeremy Foster over at codefoster.com to do two-way binding in WinJS. To do binding, the procedure is two steps. Since WinJS doesn't support two way bindings we need to define each one way binding. The first from source data to the destination and is done via WinJS.Binding.defaultBind. The second from the binding target back to the source data (in this case actually just from the input text box to the source model is done from an onchange event wiring. WinJS.Namespace.define("Binding.Mode", { twoway: WinJS.Binding.initializer(function (source, sourceProps, dest, destProps) { WinJS.Binding.defaultBind(source, sourceProps, dest, destProps); dest.onchange = function () { var d = dest[destProps[0]]; var s = source[sourceProps[0]]; if (s !== d) source[sourceProps[0]] = d; } }) }); <input type="text" data-win-bind="value: name Binding.Mode.twoway" /< That's it - super easy.