Use the disabled property to check if an element is disabled, e.g. if (element. disabled) {} . The disabled property returns true when the element is disabled, otherwise false is returned.
You can use $(":disabled") to select all disabled items in the current context. To determine whether a single item is disabled you can use $("#textbox1").is(":disabled") . Show activity on this post. With boolean comparison there is no need to test against true or 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).
Try using document.getElementById('textbox1').disabled
function CheckTextbox() {
var id;
for (var i = 1; 2 >= i; i++) {
id = 'textbox' + i;
console.log(id, 'is disabled ?', document.getElementById(id).disabled);
}
}
<input type="text" id="textbox1" disabled="disabled">
<input type="text" id="textbox2">
<input type="button" onclick="CheckTextbox();" value='Check'>
function CheckTextbox() {
var textbox = document.getElementById('textbox1');
if (textbox.disabled) {
// If disabled, do this
alert("disabled");
} else {
// Enter code here
alert("Not disabled");
}
}
<input type="text" id="textbox1" disabled="disabled">
<input type="button" onclick="CheckTextbox();">
function CheckTextbox(){
if(document.getElementById("textbox1").disabled == true){ //here
alert("disabled");
}else{
alert("enable");
}
if(document.getElementById("textbox2").disabled == true){ //here
alert("disabled");
}else{
alert("enable");
}
}
<script>
function CheckTextbox(){
var textbox=document.getElementById('textbox1');
if(textbox.disabled)
{alert("disabled"); }
else{alert("enable");}
var textbox2=document.getElementById('textbox2');
if(textbox2.disabled){ //here
alert("disabled");
}else{
alert("enable");
}
}
</script>
<input type="text" id="textbox1" disabled="disabled">
<input type="text" id="textbox2">
<input type="button" onclick="CheckTextbox();">
<input type="text" id="textbox1" disabled="disabled">
<input type="text" id="textbox2">
<input type="button" onclick="CheckTextbox();">
<script>
(function CheckTextbox(){
if(document.getElementById('textbox1').disabled){
alert("disabled");
}else{
alert("enable");
}
if(document.getElementById('textbox2').disabled){
alert("disabled");
}else{
alert("enable");
}
})()
</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