Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if textbox disabled or enabled in JavaScript

Tags:

javascript

People also ask

How check textbox is disabled or not in JavaScript?

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.

How do I know if a textbox is disabled?

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 .

How do I check if a button is enabled or disabled in jQuery?

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>