Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Set Form Fields Values</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ var text = $(this).text(); $('input[type="text"]').val(text); }); }); </script> </head> <body> <button type="button">Discovery</button> <button type="button">Atlantis</button> <button type="button">Endeavour</button> <p><strong>Note:</strong> Click the above buttons to set the value of following input box.</p> <p> <input type="text"> </p> </body> </html>