Reputation: 559
This is my first html textbox with javascript code
<div>
<input type="text" onchange="getTheValue(this)" id="12345" />
</div>
and this is my second html tag
<input type="hidden" id="12345_hiddenField" ng-model="hiddenField"/>
And on onchange
event i am calling this javascript function
function getTheValue(data) {
document.getElementById("12345_hiddenField").value = data.value;
}
i want first textbox value to be assigned to second textbox ngmodel
value with pure javascript no angualrjs methods in that, becoz that onchange
function is written in seperate pure javascript file,is their anyway to do this?
Upvotes: 0
Views: 776
Reputation: 3192
I would do it like this.
document.getElementById("12345").addEventListener('change',function() {
document.getElementById("12345_hiddenField").value = document.getElementById("12345").value;
See fiddle https://jsfiddle.net/9fh8rxck/
Upvotes: 1
Reputation: 552
<input type="text" ng-model="textboxValue" id="12345" />
and your hidden:
<input type="hidden" id="12345_hiddenField" value="{{textboxValue}}"/>
Your input text is bound to the $scope
property textboxValue
Your hidden input uses that variable as value {{textboxValue}}
, everything is 2-way data-bound.
Upvotes: 0