Get value from an input text in javascript

1

Colleagues, I have the following scenario:

I have an input

input type="text" id="myField3" name="myField3" ng-model="selected"/>

I need to play the contents of this input in a variable in javascript:

<script>
var escopo = document.getElementById('myField3').value;
console.log(escopo);
</script>

Nothing returns me in the log of the variable. The content of the input is correct.

    
asked by anonymous 26.01.2018 / 17:19

1 answer

-1

Uses the val property of jquery.

Example:

$('#idDoInput').val();//ira retornar o conteudo do input.
    
26.01.2018 / 17:23