jQuery: Access form input fields using jQuery

jQuery Practical exercise Part - I : Exercise-25

Access form input fields using jQuery.

Sample Solution:

HTML Code :

<!DOCTYPE html>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Access form input fields using jQuery</title>
<form id="myForm" action="sample.php">
First name:<br>
<input type="text" name="firstname" value="Mickey">
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<input type="submit" value="Submit">
<p> Click Submit button to get all the forms elements and their values</p>

JavaScript Code:

$('#myForm').submit(function() {
  var values = $(this).serialize();

See the Pen jquery-practical-exercise-25 by w3resource (@w3resource) on CodePen.

Contribute your code and comments through Disqus.

Previous: How to get textarea text using jQuery.
Next: Find the absolute position of an element using jQuery.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.