Two-way data binding in JavaScript
When the input is changed, update the value, add an installer to the value that sets the contents of the inputs. For example, this element:
<input id="age">
And some js:
var person = (function(el){
return {
set age(v){
el.value = v;
},
get age(){
return el.value;
}
};
})(document.getElementById("age"));
So you can do:
person.age = 15;
And the entrance will change. Changing the login changes person.age
source to share
Yes, it is quite possible. It has been used by all major javascript frameworks (angularJS, angular ...).
You will find some examples here (this is a bit outdated but should give you some ideas) http://www.lucaongaro.eu/blog/2012/12/02/easy-two-way-data-binding-in-javascript/
source to share
Yes indeed. There are frameworks like angular Js that provide full support for two way data binding. And if you want to achieve the same in vanilla js you can bind the value to the view
Eg. document.getElementById('test').value="This is a Test"
And to bind the value of the view to the controller, you can fire the onchange event in the html.
<Input type="text" id="test" onchange="Func()">
source to share