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

214
Views
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 answers
Answer question

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 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!