Pass Hidden input value to label

Asked

Viewed 717 times

0

Staff need to pass the content of a Hidden input 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 taking the variable of the input Hidden (Cad), because if I set the var value = 1; it works and the label appears

  • 1

    <label id="text">{register}}</label> would not do?

2 answers

0

Because as the type is Hidden it works like a Boolean, if you put 1 it passes to true and appears

Hidden can’t be the type, got it

0

It turns out that this input doesn’t have the value attribute that you’re picking up on JS.

Try this by placing 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.