jQuery

How to get form data with JQuery

In this tutorial, we are going to see how to get form data with JQuery. To get the values of a form with jQuery, we use the function val().
 

Script: Get form data with JQuery
<!DOCTYPE html>
<html>
   <head>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script>
         $(document).ready(function(){
             $("#get").click(function () {
                $("#output").html(
                    $("#txt").val() + "<br/>" +
                    $("input:radio[name=s]:checked").val()
                );
            });
         });
      </script>
   </head>
   <body>
      Name : <input id="txt"/>
      <br /><br />
      Gender : <input type="radio"  name="s" value="Male"/> Male
      <input type="radio"  name="s" value="Female"/> Female
      <br /><br />
      <input id="get" type="button" value="Get Data"/>
      <p id="output"></p>
   </body>
</html>
Result
Name :

Gender : Male Female

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *