Description:
In some scenario, you may need no one should
change the value of the input field. For this situation, make input fields as
readonly. So that the user cannot edit the fields.
To add readonly property using jquery,
$("#IdofTextbox").prop("readonly", true);
You can also make disable the input fields,
by setting their attributes.
$("#IdofTextbox").attr("disabled", true);
To remove readonly attribute,
set the readonly property as false.
$("#IdofTextbox").prop("readonly", false);
$("#IdofTextbox").removeAttr("readonly", true);
Example Program:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#Button1").click(function () {
$("#TextBox1").prop("readonly", true);
//
$("#TextBox1").attr("disabled", true); //We can make
Readonly by using disabled property also.
return false;
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
Disable elements using Jquery,
Add Readonly attribute with Jquery , Disable fields using Jquery, How to set
Readonly textbox using Jquery, Set Readonly property using Jquery, Set Readonly
attribute, Set a Textbox to Readonly, Jquery Disable input fields, Disable
input fields using Jquery, Add Readonly using Jquery, how to make fields
readonly using Jquery
0 comments:
Post a Comment