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

83
Views
Contenido de salida del elemento HTML en la consola

Sé sólo un poco de JavaScript. Necesito generar en mi terminal un mensaje ingresado por el usuario en un formulario html, pero mi solución JavaScript actual no muestra el resultado correcto.

HTML

 <h2 class="heading">Send e-mail to someone@example.com:</h2> <input name="myText" id="myText" type="text" placeholder="enter your message here"> <button id="btn" onclick="sendMail()">Send</button> <script src="./server.js"></script>

javascript

 console.log(document.getElementById('myText').innerText());
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Use esto y obtendrá el valor dentro de la entrada

 document.getElementById('myText').value
about 4 years ago · Juan Pablo Isaza Report

0

Puedes usar JQuery.

 $(':input').keyup(function() { console.log($(this).val()) });
about 4 years ago · Juan Pablo Isaza Report

0

¿Presumiblemente desea obtener el valor del campo de texto cuando ocurre algún tipo de evento? Asigne un controlador de eventos al elemento de entrada, así:

 document.querySelector('input[name="myText"]').addEventListener('keyup',function(e){ console.log(this.value) })
 <h2 class="heading">Send e-mail to someone@example.com:</h2> <input name="myText" id="myText" type="text" placeholder="enter your message here"> <button id="btn" onclick="sendMail()">Send</button>

Para asignar un event handler al button

 document.querySelector('button#btn').addEventListener('click',function(e){ e.preventDefault(); console.log(this.previousElementSibling.value) })
 <h2 class="heading">Send e-mail to someone@example.com:</h2> <input name="myText" id="myText" type="text" placeholder="enter your message here"> <button id="btn">Send</button>

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!