Syed Rasheed Syed Rasheed - 6 months ago 12
Javascript Question

How to give value of textbox to ngModel textbox using javascript

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?

Answer

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/

Comments