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

125
Views
Reemplazo de la palabra de tipo de entrada al hacer clic en el botón

Tengo la siguiente función JS que debería cambiar la palabra "hola" a "yo" al hacer clic en un botón si el usuario ha ingresado esto. Por ejemplo, "hola, ¿cómo estás hoy?" ==> "Oye, ¿cómo estás hoy?"

 function changeWord() { let str = document.getElementById('inputBox').innerHTML; document.getElementById('inputBox').innerHTML = str.replace("hi", "yo");; }

Lo anterior no funciona cuando llamo a changeWord(); al hacer clic, alguna idea?

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

0

Debería apuntar al valor de la entrada en lugar del HTML.

 const input = document.querySelector('input'); const button = document.querySelector('button'); button.addEventListener('click', changeWord, false); function changeWord() { const str = input.value; input.value = str.replace("hi", "yo"); }
 <input type="text" /> <button>Click</button>

about 4 years ago · Juan Pablo Isaza Report

0

Use .value en lugar de .innerHTML, así:

 let str = document.getElementById('inputBox').value; document.getElementById('inputBox').value = str.replace("hi", "yo");
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!