Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

503
Views
Check if textbox disabled or enabled in JavaScript

How do I check if a textbox is disabled or enabled in JavaScript? I just want to know if a textbox is enable or disabled on button click. If the textbox is disabled I want to alert the user with the message "disabled" and if it is enable, the alert message will be "enabled".

<script>
 function CheckTextbox(){

    if(textbox1 is disabled){ //here
      alert("disabled");
    }else{
      alert("enable");
    }

   if(textbox2 is 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();">
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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'>

over 4 years ago · Santiago Trujillo Report

0

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();">

over 4 years ago · Santiago Trujillo Report

0

function CheckTextbox(){

    if(document.getElementById("textbox1").disabled){ //here
       alert("disabled");
    }else{
      alert("enabled");
     }


   if(document.getElementById("textbox2").disabled) { //here
      alert("disabled");
   }else{
      alert("enabled");
   }

}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!