// Here except Email and Password field alone will not be cleared remaing fileds will be cleared.
// class="ClearForm" because not exist.
// class="ClearForm Corner" this is multiple class style. You can add more than one class style to
// htmal tag.
// class="ClearForm" because not exist.
// class="ClearForm Corner" this is multiple class style. You can add more than one class style to
// htmal tag.
<!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>
<title></title>
<script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
(function ($) {
$.fn.clearForm = function () {
return this.each(function () {
var obj = $(this);
var objClass = '.ClearForm';
obj.find('[type="text"]' + objClass + ',[type="password"]' + objClass + ',[type="hidden"]' + objClass + ',textarea' + objClass).val('');
obj.find('[type="checkbox"]' + objClass + ',[type="radio"]' + objClass).attr('checked', false);
obj.find('select' + objClass).val(-1);
});
};
})(jQuery);
</script>
<script type="text/javascript">
// Here Email and Password field alone will not be cleared. class="ClearForm" because not exist.
$(document).ready(function () {
$('#btnClearForm').click(function () {
$('#form1').clearForm();
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
</td>
<td>
<input type="text" id="tbEmail" class=" Corner" />
</td>
</tr>
<tr>
<td>
Password
</td>
<td>
<input type="password" id="tbPassword" class="Corner" />
</td>
</tr>
<tr>
<td>
HiddenValue
</td>
<td>
<input type="hidden" id="hdnHiddenValue" class="ClearForm Corner" />
</td>
</tr>
<tr>
<td>
Details
</td>
<td>
<textarea style="width: 300px; height: 300px;" id="tbDetails" class="ClearForm Corner"></textarea>
</td>
</tr>
<tr>
<td>
Sex
</td>
<td>
<input type="radio" value="Male" name="rblSex" class="ClearForm RedColor" />Male<br />
<input type="radio" value="Female" name="rblSex" class="ClearForm RedColor" />Female
</td>
</tr>
<tr>
<td>
Property
</td>
<td>
<input type="checkbox" value="Car" name="cbProperty" class="ClearForm RedColor" />Car<br />
<input type="checkbox" value="House" name="cbProperty" class="ClearForm RedColor" />House<br />
<input type="checkbox" value="Van" name="cbProperty" class="ClearForm RedColor" />Van<br />
</td>
</tr>
<tr>
<td>
Status
</td>
<td>
<select id="ddlStatus" class="ClearForm RedColor">
<option>Select</option>
<option value="single">single</option>
<option value="married">married</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" id="btnClearForm" value="Clear Form" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
No comments:
Post a Comment