Q:

How to disable all input controls inside a form using jQuery

0

How to disable all input controls inside a form using jQuery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this 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.

Let's check out an example to understand how this method basically works:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Disable All Form Elements</title>
<style>
    label {
        display: block;
        margin-bottom: 5px;
    }
    label, input, textarea, select {
        margin-bottom: 10px;
    }
</style>
<script src="https://code.jquery.com/jquery-3.5.1.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>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>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to check or uncheck radio button dynamically u... >>
<< How to disable or enable a form element using jQue...