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

246
Views
¿Cómo concatenar usando getElementbyID en un elemento de lista?

aquí está el código

 <h1>Timeworn Kumbhiraskin Maps</h1> <label for="room">What chamber did you reach?</label> <select id="room"> <option value="none">No portal</option> <option value="first">First Chamber</option> <option value="second">Second Chamber</option> <option value="third">Third Chamber</option> <option value="fourth">Fourth Chamber</option> <option value="fifth">Final Chamber</option> </select> <ul id="percentages"> <li id="np">No portal: </li> <li id="firstC">First Chamber: </li> <li id="secondC">Second Chamber: </li> <li id="thirdC">Third Chamber: </li> <li id="fourthC">Fourth Chamber:</li> <li id="fifthC">Final Chamber: </li> </ul> </body> </html>
 var totalMaps = 0; var pPortal = 0; var pFirst = 0; var pSecond = 0; var pThird = 0; var pFourth = 0; var pFifth = 0; window.onload = function(){ document.getElementById("np").value += string(pPortal); document.getElementById("firstC").value += string(pFirst); document.getElementById("secondC").value += string(pSecond); document.getElementById("thirdC").value += string(pThird); document.getElementById("fourthC").value += string(pFourth); document.getElementById("fifthC").value += string(pFifth); }

Básicamente, solo estoy teniendo problemas con el javascript. Quiero mostrar las variables de javascript en la lista, pero no se muestra. ¿Alguna ayuda? ¿Estoy haciendo algo mal? Probé algunos métodos diferentes y busqué en línea, pero parece que nadie tiene la respuesta que estoy buscando.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Si desea convertir una variable en una cadena, tiene para usted la función String() (sensible a mayúsculas y minúsculas). También te perdiste la parte que decía innerHTML. Esto es trabajo para mí

 <body> <ul id="percentages"> <li id="np">No portal: </li> <li id="firstC">First Chamber: </li> <li id="secondC">Second Chamber: </li> <li id="thirdC">Third Chamber: </li> <li id="fourthC">Fourth Chamber:</li> <li id="fifthC">Final Chamber: </li> </ul> </body> <style> body {padding: 0.5rem 1rem;} </style> <script> let totalMaps = 0; let pPortal = 0; let pFirst = 0; let pSecond = 0; let pThird = 0; let pFourth = 0; let pFifth = 0; window.onload = function(){ document.getElementById("np").innerHTML += String(pPortal); document.getElementById("firstC").innerHTML += String(pFirst); document.getElementById("secondC").innerHTML += String(pSecond); document.getElementById("thirdC").innerHTML += String(pThird); document.getElementById("fourthC").innerHTML += String(pFourth); document.getElementById("fifthC").innerHTML += String(pFifth); } </script>
about 4 years ago · Santiago Trujillo Report

0

Prueba esto

 document.getElementById('np').innerHTML += pPortal;

... etc. El operador JS + convierte automáticamente su tipo de número en una cadena en este caso.

about 4 years ago · Santiago Trujillo 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!