<!DOCTYPE html>
<html>
<head>
<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>
</head>
<body>
<form id="myForm" action="sample.php">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
<p> Click Submit button to get all the forms elements and their values</p>
</body>
</html>
JavaScript Code:
$('#myForm').submit(function() {
var values = $(this).serialize();
console.log(values);
});
JavaScript Code: