Reputation: 77
I have a button in my application :
<button name="download" id="download" type="submit" class="btn primary" style="margin:0;">Next</button>
How can I disable this button and re-enable it using JQuery ?
I tried below code but it doesn't works.
$('#download').attr('disabled', 'disabled');
$('#download').removeAttr('disabled');
TIA :)
Upvotes: 1
Views: 1604
Reputation: 3305
Try something like this,
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>
//<![CDATA[
$(window).load(function(){
$('button#download').prop('disabled', true);
alert('hello');
$('button#download').removeAttr('disabled');
});
//]]>
</script>
</head>
<body>
<button name="download" id="download" type="submit" class="btn primary" style="margin:0;">Next</button>
</body>
</html>
Upvotes: 1
Reputation: 4637
Below code if you have text box that is empty
the submit button ill be disbaled if the textbox is not empty
submit button not disabled
$(document).ready(function() {
$('input[type="submit"]').attr('disabled','disabled');
$('input[type="text"]').keyup(function() {
if($(this).val() != '') {
$('input[type="submit"]').removeAttr('disabled');
}
});
});
Upvotes: 0