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

153
Vistas
JavaScript delete sentences add new default sentences with regex

Hi I'm learning java script. I am currently trying to figure out the regex. I want to try the option when I enter something in the text area field, to automatically click on the button to delete the text entered in the field and print the regex text some that will be the default, and to replace HTML entities with their visual display: & amp; in &, & nbsp; with a space, & quot; with quotation marks.

<!DOCTYPE html>
<html>
<body>

<textarea id="demo" name="w3review" rows="4" cols="50">

  </textarea>
  <br>
  <button id="btnText" onclick="tipka()">click</button>
<script>
function tipka(){
let str = document.getElementById("demo").innerHTML; 
let res = str.replace(/abc/g, "Lorem Ipsum is simply dummy text of the printing and typesetting industry.");
document.getElementById("demo").innerHTML = res;}
</script>

</body>
</html>

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

If i understand question there should be document.getElementById("demo").value not document.getElementById("demo").innerHTML

<!DOCTYPE html>
<html>
<body>

<textarea id="demo" name="w3review" rows="4" cols="50">

  </textarea>
  <br>
  <button id="btnText" onclick="tipka()">click</button>
<script>
function tipka(){
let str = document.getElementById("demo").value; 

let res = str.replace(/abc/g, "Lorem Ipsum is simply dummy text of the printing and typesetting industry.");
document.getElementById("demo").value= res;
}
</script>

</body>
</html>

about 4 years ago · Juan Pablo Isaza Denunciar

0

The solution requires a few changes :

  1. Inside tipka, the function should read the value of the textarea instead of the innerHTML.
  2. Similarly, while replacing the text, set the value of the textfield instead of innerHTML.

See Setting innerHTML vs. setting value with Javascript

Here's the snippet working with the suggested changes :

<!DOCTYPE html>
<html>
<body>

  <textarea id="demo" name="w3review" rows="4" cols="50">
  </textarea>
  <br>
  <button id="btnText" onclick="tipka()">click</button>

  <script>
    function tipka() {
      let str = document.getElementById("demo").value;
      let res = str.replace(/abc/g, "Lorem Ipsum is simply dummy text of the printing and typesetting industry.");
      document.getElementById("demo").value = res;
    }
  </script>

</body>
</html>

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