I'm trying to clear my input field's ,but when i clear them php pushes empty string to my database .could someone help me?
this is my code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="style.css">
<title>Document</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function () {
$('form').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'phpAdd.php',
data: $('form').serialize(),
success: function () {
alert('form was submitted');
}
});
});
});
function submitForm(){
var form = document.getElementById("myForm");
form.reset();
$('#firstname').focus();
}
</script>
</head>
<body>
<center>
<form action="phpAdd.php" method="post" id="myForm">
<h1>Please enter your info.</h1>
First Name: <input type="text" name="firstname" id="firstname" class="firstname"><br>
Last Name: <input type="text" name="lastname" id="lastname" class="lastname"> <br>
<input type="submit" value="SUBMIT" class="SUBMIT" onclick="submitForm()">
</form>
</center>
</body>
</html>
how could i clear the field's after it pushes the data to php?