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

120
Vistas
¿Cómo visualizo correctamente la entrada HTML del formulario?

Mi código no funciona como pretendo y no sé cómo solucionarlo. Por lo tanto, cada vez que la persona escribe 'hola' en el cuadro y luego presiona Enviar, se supone que el párrafo que dice hola debe mostrar 'buen trabajo', pero no es así.

 <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <textarea id="thesearchh" style="resize: none;"></textarea> <button onclick="submitSearch()">Submit</button> <p id="searchResult">hi</p> <script> function submitSearch() { if(document.getElementById('thesearchh').includes('hello') == true) { document.getElementById('searchResult').innerHTML = 'good job'; } } </script> </body> </html>

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

0

Acabo de agregar .value en su código

 <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <textarea id="thesearchh" style="resize: none;"></textarea> <button onclick="submitSearch()">Submit</button> <p id="searchResult">hi</p> <script> function submitSearch() { if(document.getElementById('thesearchh').value.includes('hello') == true) { document.getElementById('searchResult').innerHTML = 'good job'; } } </script> </body> </html>

aquí puedes ver la línea iam added .value

 if(document.getElementById('thesearchh').value.includes('hello') == true){}
about 4 years ago · Juan Pablo Isaza Denunciar

0

debe verificar el valor de entrada con document.getElementById ( includes document.getElementById(inputId).value no con el método de inclusión. incluye métodos que funcionan en matrices y cadenas, pero no en elementos DOM.

 <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <textarea id="thesearchh" style="resize: none;"></textarea> <button onclick="submitSearch()">Submit</button> <p id="searchResult">hi</p> <script> function submitSearch() { if(document.getElementById('thesearchh').value === "hello") { document.getElementById('searchResult').innerHTML = 'good job'; } } </script> </body> </html>

about 4 years ago · Juan Pablo Isaza Denunciar

0

  • Deje de usar atributos en línea como: style CSS y JS on* controladores. CSS y JS deben estar en sus respectivas etiquetas o archivos.
  • Use Element.addEventListener() en lugar del controlador de atributo onclick
  • Use InputElement.value para obtener un valor de :input ( <textarea> en su caso).
  • Use === para compararlo con la cadena "hello" deseada
  • PD: ¿estás seguro de que necesitas un <textarea> en lugar de <input type="text"> ?
  • Además, es posible que desee utilizar String.prototype.trim() para eliminar los espacios en blanco de la cadena de entrada del usuario antes de comparar. Eso depende de usted.

 <!DOCTYPE html> <html> <head> <title>Page Title</title> <style> #search { resize: none; } </style> </head> <body> <textarea id="thesearchh"></textarea> <button type="button" id="thesubmitt">Submit</button> <p id="searchResult">hi</p> <script> // DOM Utility functions: const el = (sel, par) => (par??document).querySelector(sel); // Task: Match value "hello": const elSearch = el("#thesearchh"); const elSubmit = el("#thesubmitt"); const elResult = el("#searchResult"); const submitSearch = () => { const userInput = elSearch.value; if (userInput === "hello") { elResult.textContent = 'good job'; } }; elSubmit.addEventListener("click", submitSearch); </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