Pass input value hidden to label

0

Personal I need to pass the contents of an input hidden to a label:

<div class="form" ng-init="rodar()">
<input type="hidden" ng-model="cadastro" name="cad" id="cad">
<label id="text"></label> 
<script>
    function rodar()
    { 
        var valor = document.getElementById('cad').value; 
        document.getElementById('text').innerHTML = valor;
    } 
    window.onload = rodar(); 
</script>

From what I saw the error is when I get the variable of the input hidden (cad), because if I set the var value = 1; it works and the

    
asked by anonymous 12.01.2018 / 19:37

2 answers

0

Because the type is hidden it works like a boolean, if you put 1 it passes to true and appears

hidden can not be type, understood

    
12.01.2018 / 20:05
0

It turns out that this input does not have the value attribute that you are getting in JS.

Try this, putting the value attribute in the input:

<div class="form" ng-init="rodar()"> <input type="hidden" ng-model="cadastro" name="cad" id="cad" value="Teste"> <label id="text"></label> <script> function rodar() { var valor = document.getElementById('cad').value; document.getElementById('text').innerHTML = valor; } window.onload = rodar(); </script>

    
13.01.2018 / 18:13