I am using jquery to disable the submit button and load loading image,
In submit button I am using the folowing :
<div id="registerbtn" name="registerbtn">
<input type="submit" class="btn btn-primary" icon="ok white" value="Register" id="register" name="register"/>
</div>
<div class="span4" style="display:none;" id="loadingtext">
<?php echo $imghtml=CHtml::image('images/loading.gif');?>
</div>
and in JQuery, I am using following code :
$(document).ready(function() {
$('#register').click(function() {
$('input[type="submit"]').attr('disabled','disabled');
});
$("#loadingtext").show();
});
});
When I do this, then this button is disabled permanently, but if I want to remove then what should I do ??
Given an HTML document and the task is to enable or disable the form submit button in jQuery. Approach: To enable or disable the form submit button, we use the below code snippet. $('#enabled'). click(function () { if ($('#submit-button').is(':disabled')) { $('#submit-button').
To disable a button using only JavaScript you need to set its disabled property to false . For example: element. disabled = true . And to enable a button we would do the opposite by setting the disabled JavaScript property to false .
Checking if the button is disabled or enabled with jQuery removeAttr('disabled'); }; const checkButton = (e) => { const isDisabled = $('#my-button'). prop('disabled'); if( isDisabled ){ alert("Is disabled!"); } else{ alert("Is enabled"); } }; $(document).
Use .prop()
method and use the $(this)
to reference the target element within the callback function
jQuery(function($) {
const $register = $("#register"),
$loading = $("#loading");
$register.on("click", function() {
$(this).prop('disabled', true);
$loading.show();
setTimeout(function() {
$register.prop('disabled', false);
$loading.hide();
}, 2000);
});
});
<input id="register" value="Register" type="submit">
<div id="loading" style="display:none;">Wait 2 sec...</div>
<script src="//code.jquery.com/jquery-3.1.0.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With