Here I will explain how to
use jQuery to enable
disable textbox based on checkbox selection / click or jQuery enable disable textbox on checkbox click or jQuery enable disable textbox when checkbox selected
/ deselected or enable disable textbox on checkbox selection using jQuery with example.
To enable or disable textbox based on checkbox selection need to write the code like as shown below
<script type="text/javascript">
$(function () {
$('#chkSelect').change(function () {
var status = this.checked;
if (status)
$('#txtUsername').prop("disabled", false);
else
$('#txtUsername').prop("disabled", true);
})
})
</script>
If you want to check it in complete example you need to write the code like as shown below:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Enable or Disable Textbox on Checkbox Selection</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function () {
$('#chkSelect').change(function () {
var status = this.checked;
if (status)
$('#txtUsername').prop("disabled", false);
else
$('#txtUsername').prop("disabled", true);
})
})
</script>
</head>
<body>
<form id="form1">
<div>
Select Checkbox: <input type="checkbox" id="chkSelect" checked="checked" /><br />
Enter UserName:<input type="text" id="txtUsername" />
</div>
</form>
</body>
</html>
No comments:
Post a Comment