Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
Assign dynamic value to an Input Field in HTML

I have an input field and I want to assign it a value dynamically fetched from DB. I will use that value later in a script. Here is my code below

<div data-ng-model="DashboardCounterItems">
<div data-ng-repeat="cItem in DashboardCounterItems">
<input type ="hidden" id ="myInput" value = {{cItem.dbMeetings.length}} />
</div>
</div>

Here {{cItem.dbMeetings.length}} is fetched from DB and assigned to myInput. Further when I check the value of this input in alert in script below, I get {{cItem.dbMeetings.length}} message instead of the value within it.

<script>
var iLenthv = document.getElementById("myInput").value;
alert(iLenthv);
</script>

Any help how can I do it. Or any other better way. I will really appreciate it.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

I think your JS code will execute before DB data retrieval, can you check JS code within the setTimeout() Method?

<script>
    setTimeout(function() {
        var iLenthv = document.getElementById("myInput").getAttribute("value");
        alert(iLenthv);
    }, 3000); 
</script>
about 4 years ago · Juan Pablo Isaza Relatório

0

Use .getAttribute() to get the value from a html attribute

function myFunction() {
var iLenthv = document.getElementById("myInput").getAttribute("value"); 
alert(iLenthv);
}

Hope it's helpfull

about 4 years ago · Juan Pablo Isaza Relatório

0

So we have to track the client side actual value, after the document is loaded. Would you adapt this piece of code and take a look at the console ?

<div data-ng-model="DashboardCounterItems">
  <div data-ng-repeat="cItem in DashboardCounterItems">
    <input type="hidden" id="myInput" value={{cItem.dbMeetings.length}} />
  </div>
</div>

<script>
  const test = () => {
    var iLenthv = document.getElementById("myInput").value;
    console.log("value:",iLenthv);
  };

  window.onload = test;
</script>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda