posted 1/27/2011 by Raghav Khunger
I saw a person asking on forums on how to disable all the input fields on a form with jQuery. I decided to write a blog on this. User will click a button and all the input feilds of the form will get disabled. Below is the code for it:
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.8/themes/base/jquery-ui.css" type="text/css" media="all" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function() { $('input[id$=\'TestButton\']').click(function() { $('input, select, textarea').not(this).attr('disabled', 'disabled'); return false; }); }); </script> </head> <body> <form id="form1" runat="server"> <asp:TextBox runat="server"></asp:TextBox> <br /> <asp:DropDownList runat="server"> <asp:ListItem>Text1</asp:ListItem> <asp:ListItem>Text2</asp:ListItem> </asp:DropDownList> <br /> <asp:TextBox runat="server" TextMode="MultiLine"></asp:TextBox> <br /> <asp:ListBox runat="server"> <asp:ListItem>Text1</asp:ListItem> <asp:ListItem>Text2</asp:ListItem> </asp:ListBox> <asp:Button ID="TestButton" runat="server" Text="Test" /> </form> </body>
Do let me know your feedback, comments.
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18