1
Hello, I need to select the value that is inside an input, the value is variable from 1 to 12, but I do not know how to do it, here is the input HTML:
<input type="text" id="mudarUnidadePacote" class="input-quantity ng-pristine ng-valid ng-not-empty ng-touched" value="0" ng-model="ctrl.boxQuantity" ng-blur="ctrl.updateBoxQuantity()" packsize="12">
This is my code (it appears that I was able to select the element but the number does not appear, between 0 and 12).
let quantidade = document.getElementById("mudarUnidadePacote").textContent;
alert(quantidade)
Vinicius,
textContent
picks up a text node that is the child ofinput
. However inputs do not have children because they are not containers. What you want is the propertyvalue
ofInputHTMLElement
– fernandosavio
And it would be nice if you [Edit] your question and add the tags of the frameworks you are using because
ng-model
is not part of the default HTML and can completely change the most advised answer for your case.– fernandosavio
@fernandosavio I beg your pardon, my first question here in the stack, in case the framework is Angular.
– Vinicius