Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
Asignar valor dinámico a un campo de entrada en HTML

Tengo un campo de entrada y quiero asignarle un valor obtenido dinámicamente de DB. Usaré ese valor más adelante en un script. Aquí está mi código a continuación

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

Aquí {{cItem.dbMeetings.length}} se obtiene de la base de datos y se asigna a myInput. Además, cuando verifico el valor de esta entrada en alerta en el siguiente script, obtengo el mensaje {{cItem.dbMeetings.length}} en lugar del valor que contiene.

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

Alguna ayuda como puedo hacerlo. O cualquier otra forma mejor. Realmente lo apreciaré.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Creo que su código JS se ejecutará antes de la recuperación de datos DB, ¿puede verificar el código JS dentro del método setTimeout () ?

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

0

Use .getAttribute() para obtener el valor de un atributo html

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

Espero que sea útil

about 4 years ago · Juan Pablo Isaza Report

0

Así que tenemos que rastrear el valor real del lado del cliente, después de cargar el documento . ¿Adaptarías este fragmento de código y echarías un vistazo a la consola?

 <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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!