prop()
methodYou can simply use the jQuery prop()
method to disable or enable form elements or controls like <input>
, <select>
, <textarea>
, etc. dynamically using jQuery.
The prop()
method require jQuery 1.6 and above. Let's see how this works:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Disable or Enable an Input with jQuery</title>
<style>
label {
display: block;
margin: 10px 0;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
$('form input[type="submit"]').prop("disabled", true);
$(".agree").click(function(){
if($(this).prop("checked") == true){
$('form input[type="submit"]').prop("disabled", false);
}
else if($(this).prop("checked") == false){
$('form input[type="submit"]').prop("disabled", true);
}
});
});
</script>
</head>
<body>
<form>
<label>Name: <input type="text" name="username"></label>
<label>Email: <input type="email" name="email"></label>
<label><input type="checkbox" class="agree"> I agree to terms and conditions.</label>
<input type="submit" value="Submit">
</form>
</body>
</html>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to Trigger a Click on a Link Using jQuery
Use the jQuery click() Method You can...Using the $loop variable in foreach loops in Laravel Blade
Laravel provides simple blade template w...Laravel 7 - User Roles and Permissions Tutorial without Packages
Roles and sanctions are a paramount part...How to create a query string from an array in PHP
When sending get request to third party...React Responsive Animated Navbar Example
In this article, I will share with you h...