jQuery <form> disable all input controls inside form

Description

jQuery <form> disable all input controls inside form

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Disable All Form Elements</title>
<style>
  label {//from   w  w w. j a  v a2s . c  o m
    display: block;
    margin-bottom: 5px;
  }
    label, input, textarea, select {
        margin-bottom: 10px;
    }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
    $(document).ready(function(){
    $("#myForm :input").prop("disabled", true);
    });
</script>
</head>
<body>
  <form id="myForm">
      <label>Name:</label>
        <input type="text">
        <label>Gender:</label>
        <label><input type="radio" name="sex"> Male</label>
        <label><input type="radio" name="sex"> Female</label>
        <label>Hobbies:</label>
        <label><input type="checkbox" name="sports"> CSS</label>
        <label><input type="checkbox" name="sports"> HTML</label>
        <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>



PreviousNext

Related