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

153
Views
Estoy tratando de usar una entrada HTML de usuario para cambiar el valor de un objeto javascript

Estoy tratando de usar HTML 'entrada' para cambiar el valor de apiData.id. Soy nuevo en javascript y no estoy seguro si esto es correcto. Cualquier sugerencia sería muy apreciada.

 const apiData = { url: 'https://pokeapi.co/api/v2/', type: 'pokemon', id: '76', } const input = document.getElementById('container'); const newId = apiData.id; function eventController(event) { newId = event.target.value; } input.addEventListener('change', eventController, false);
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Pokemon</title> <link rel="stylesheet" href="style.css"> </head> <body> <div id="container"> <input id="input"> <input type="submit" value="Catch"> </div> <div class="pokemon"></div> <script src="main.js"></script> </body> </html>

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

0

newId es constante, por lo que no puede asignarle un nuevo valor después de que se haya declarado.

Pero incluso si pudiera (y puede, al convertirlo en una variable), eso no afectaría a apiData.id , ya que a newId se le asigna el valor de apiData.id , pero no están vinculados entre sí.

Simplemente debe asignar apiData.id directamente con un nuevo valor:

 const apiData = { url: 'https://pokeapi.co/api/v2/', type: 'pokemon', id: '76', } const input = document.getElementById('container'); // const newId = apiData.id; function eventController(event) { apiData.id = event.target.value; } input.addEventListener('change', eventController, false);
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Pokemon</title> <link rel="stylesheet" href="style.css"> </head> <body> <div id="container"> <input id="input"> <input type="submit" value="Catch"> </div> <div class="pokemon"></div> <script src="main.js"></script> </body> </html>

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!