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

211
Vistas
Input box alerts the text by clicking a button (Really new to JQuery)

JQuery Part

I just started using JQuery. First I wanted to create a a input box with an button that alerts the text that is in that box. This is the way I wanted to do that.

$(document).ready(function() { 
  $('#hit').click(function() { 
    alert($('#term').val());
  });
});

That is the code in the html body part. Here im not sure if I have to declare the id with an # or not. I tried both but It didnt work for both.

My Code

<!DOCTYPE html> 
<html>
   <head>
      <title>Button Event</title>
      <script src="cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"> $(document).ready(function() { $('#hit').click(function() { alert($('#term').val()); }); }); </script> 
   </head>
   <body> <input id="term" type="text" value="enter your search"> <button id="hit" type="button" name="Button">Search</button> </body>
</html>

I am really new to JavaScript and Jquery. When I run this code there are no errors or something like that in the console just blank. The Button and Input field are on the website but when I enter something and click the button after that nothing happens. That´s why im sure there are some mistakes in that code.

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

0

$(document).ready(function() { 
  $('#hit').click(function() { 
    alert($('#term').val());
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="term" type="text" value="enter your search" />
    <button id="hit" type="button" name="Button">Search</button>

here has worked, do you have imported a jquery library?

Resolution with your code:

<!DOCTYPE html> 
<html>
   <head>
      <title>Button Event</title>
   </head>
   <body> <input id="term" type="text" value="enter your search"> <button id="hit" type="button" name="Button">Search</button>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script>
         $(document).ready(function() { $('#hit').click(function() { alert($('#term').val()); }); });
      </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