How to disable all input controls inside a form using jQuery

Topic: JavaScript / jQuery« Prev|Next »

Answer: Use the jQuery prop() method

You can use the jQuery prop() method in combination with the :input selector to disable all <input>, <textarea>, <select> and <button> elements inside an HTML form dynamically using jQuery. The prop() method require jQuery 1.6 and above.

  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <title>jQuery Disable All Form Elements</title>
  • <style type="text/css">
  •     label {
  •         display: block;
  •         margin-bottom: 5px;
  •     }
  •     label, input, textarea, select {
  •         margin-bottom: 10px;
  •     }
  • </style>
  • <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
  • <script type="text/javascript">
  •     $(document).ready(function(){
  •         $("#myForm :input").prop("disabled", true);
  •     });
  • </script>
  • </head>
  • <body>
  •     <form id="myForm">
  •         <label>Name:</label>
  •         <input type="text">
  •         <label>Address:</label>
  •         <textarea></textarea>
  •         <label>Country:</label>
  •         <select>
  •             <option>select</option>
  •         </select>
  •         <br>
  •         <button type="button">Submit</button>
  •         <button type="button">Reset</button>
  •     </form>
  • </body>
  • </html>

Related FAQ

Here are some more FAQ related to this topic:

 
Close

Your Feedback:

 

We would love to hear from you! Please say something.