Reputation: 19
How to disable form (user cannot checked, fill text , select drop down etc.) in this form when process requests post ajax ?
i want to disable form id="f1"
when process send post ajax , How can i do that ?
<script>
function send_requests_data(){
$('#demoajax').hide();
$('#loading').show();
$.ajax({
url: 'test.php',
type: 'POST',
data: $('#f1').serialize(),
success: function(data){
$("#loading").fadeOut("slow");
$('#demoajax').show();
$('#demoajax').html(data);
}
});
return false;
}
// on load page call function code //
$(document).ready(send_requests_data());
</script>
Upvotes: 0
Views: 149
Reputation: 487
You can call the below function before calling your ajax function. It will disable all your form controls
function disable() {
var limit = document.forms[0].elements.length;
for (i=0;i<limit;i++) {
document.forms[0].elements[i].disabled = true;
}
}
Upvotes: 0
Reputation: 1814
$.each($('input, select ,textarea', '#f1'),function(){
$(this).prop('disabled', true);
});
Upvotes: 0
Reputation: 122
A possible answer may be found here: disable all form elements inside div
TL;DR try adding this:
$("#parent-selector :input").attr("disabled", true);
to the ajax call where parent-selector is either the div or form id.
Upvotes: 3
Reputation: 1495
try this i hope it helps :
function send_requests_data(){
$('#id1 input,select').attr('disabled','disbaled');
$('#demoajax').hide();
$('#loading').show();
$.ajax({
url: 'test.php',
type: 'POST',
data: $('#f1').serialize(),
success: function(data){
$("#loading").fadeOut("slow");
$('#demoajax').show();
$('#demoajax').html(data);
$('#id1 input,select').removeAttr('disabled');
}
});
return false;
}
Upvotes: 0