mazhar  khan

mazhar khan

  • 1.5k
  • 137
  • 4k

javascript

May 12 2015 10:00 AM

<script type="text/javascript" src="scripts/jquery-1.3.2-vsdoc2.js"></script>

<script type="text/javascript">

// editor1
var Editor1 = '#Editor1';
var Editor1CountLimit = 50
var Editor1InfoArea = '#Info';

// editor2

var Editor2 = '#Editor2';
// var Editor2Countlimit1 = 50
// var Editor2InfoArea = '#Info1';


$(document).ready(function () {
TrackCharacterCount(Editor1, Editor1CountLimit, Editor1InfoArea);
TrackCharacterCount(Editor2, Editor2Countlimit, Editor2InfoArea);

});



function TrackCharacterCount(ctl, limit, info) {
var editor = $(ctl).contents().find('iframe').eq(2);
$(editor).load(function () {
var txt = $(this).contents().find('body').text();
$(info).html(txt.length); //set initial value
$(this).contents().keyup(function () {
var txt = $(this).contents().find('body').text();

if (txt.length > limit)
$(info).html(txt.length).css("color", "red");
else
$(info).html(txt.length).css("color", "");
});
});
}



function ValidateEditor1Length(source, args) {
var editor = $(Editor1).contents().find('iframe').eq(2);
var txt = editor.contents().find('body').text();
var isValid = txt.length > 0 && txt.length <= Editor1CountLimit;
args.IsValid = isValid;
}



function ValidateEditor1Length2(source, args) {
var editor = $(Editor2).contents().find('iframe').eq(2);
var txt = editor.contents().find('body').text();
var isValid = txt.length > 0 && txt.length <= Editor1CountLimit;
args.IsValid = isValid;
}



</script>



</head>
<body>
<form id="form1" runat="server">
<div>

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<div id="Info">Info</div>
<cc2:Editor ID="Editor1" runat="server" InitialCleanUp="True" NoScript="True" />
<%--<custom:CustomEditor ID="Editor1"
Width="500px" Height="200px" runat="server" /> --%>

<br />
<br />

<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="Editor1"
ClientValidationFunction="ValidateEditor1Length"
ErrorMessage="Maximum 50 Character Limit"></asp:CustomValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="Editor1" ErrorMessage="Enter Text" Visible="True"
EnableViewState="False"></asp:RequiredFieldValidator>


<br />
<br />
<br />

<cc2:Editor ID="Editor2" runat="server" InitialCleanUp="True" NoScript="True" />

<asp:CustomValidator ID="CustomValidator2" runat="server" ControlToValidate="Editor2"
ClientValidationFunction="ValidateEditor1Length2"
ErrorMessage="Maximum 50 Character Limit"></asp:CustomValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="Editor2" ErrorMessage="Enter Text" Visible="True"
EnableViewState="False"></asp:RequiredFieldValidator>



<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />


</div>
</form>
</body>
</html>


Answers (1)