Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda