My form validate is working well, response message shows with form validate true / false, it's no problem but I want to add a condition in JavaScript to check if response is true then form input will be disabled until response true message will be shown then after few seconds form will be reset.
Here is my PHP code after validation and send response true:
$response = "form submitted successfully";
This is my form code sample:
<form action="" method="POST" id="headersignupform" onsubmit="return false;">
<div class="resultsignup toppage"></div>
<button type="submit" class="signupbtn">Submit</button>
and this is my JavaScript code:
<script type="text/javascript">
$(function(){
$('.signupbtn').click(function(){
$('html, body').animate({
scrollTop: $(".toppage").offset().top - 100
},'slow');
$.post("<?php echo base_url();?>account/signup",$("#headersignupform").serialize(),
function(response){
if($.trim(response) == 'true'){
document.getElementById("headersignupform").reset();
$(".resultsignup").html(response).fadeIn("slow");
}else{
$(".resultsignup").html(response).fadeIn("slow");
} }); });
})
</script>
Thus can reset it but only one time. Please read more info in below; $('#headersignupform')[0].reset();
but the reset only work one time, I mean if I refresh the page, then I click on submit button then it will show response but lets see we had so false response, then for second time or more if I will click on submit button then it won't show response at all. so, what's the issue? By the way, however the above code line reset the form, but it won't disable form input as my mentioned question.