JQuery for Html editor to limit charecter

Jun 6 2011 4:26 AM
function limitChars(textid, limit, infodiv) {




var text = $('#' + textid).val();

var textlength = text.split(' ').length;

if (textlength > limit+1) {

$('#' + infodiv).html('You cannot write more then ' + limit + ' words!');

alert("word limit exeed..!!")

$('#' + textid).val(text.substr(0, limit));

return false;

}

else {

$('#' + infodiv).html('You have ' + (limit - textlength) + ' Words left.');

return true;

}

}



$(document).ready(function() {

$('#ctl00_Content_TxtResponseOne_ctl02_ctl01').keyup(function() {



limitChars('ctl00_Content_TxtResponseOne_ctl02_ctl01', 200, 'ctl00_Content_ROneCount');

})

$('#ctl00_Content_TxtResponseTwo_ctl02_ctl01').keyup(function() {

limitChars('ctl00_Content_TxtResponseTwo_ctl02_ctl01', 500, 'ctl00_Content_RTwoCount');

})

$('#ctl00_Content_TxtResponseThree_ctl02_ctl01').keyup(function() {

limitChars('ctl00_Content_TxtResponseThree_ctl02_ctl01', 500, 'ctl00_Content_RThreeCount');

})

$('#ctl00_Content_TxtResponseFour_ctl02_ctl01').keyup(function() {

limitChars('ctl00_Content_TxtResponseFour_ctl02_ctl01', 1000, 'ctl00_Content_RFourCount');

})

$('#ctl00_Content_TxtResponseFive_ctl02_ctl01').keyup(function() {

limitChars('ctl00_Content_TxtResponseFive_ctl02_ctl01', 500, 'ctl00_Content_RFiveCount');

})

$('#ctl00_Content_TxtResponseSix_ctl02_ctl01').keyup(function() {

limitChars('ctl00_Content_TxtResponseSix_ctl02_ctl01', 500, 'ctl00_Content_RSixCount');

})

$('#ctl00_Content_TxtResponseSeven_ctl02_ctl01').keyup(function() {

limitChars('ctl00_Content_TxtResponseSeven_ctl02_ctl01', 500, 'ctl00_Content_RSevenCount');

})

$('#ctl00_Content_TxtResponseEight_ctl02_ctl01').keyup(function() {

limitChars('ctl00_Content_TxtResponseEight_ctl02_ctl01', 500, 'ctl00_Content_REightCount');

})

$('#ctl00_Content_TxtResponseNine_ctl02_ctl01').keyup(function() {

limitChars('ctl00_Content_TxtResponseNine_ctl02_ctl01', 800, 'ctl00_Content_RNineCount');

})

});




<
table width="100%" border="0" cellpadding="0" cellspacing="0" runat="server" id="Table1">

<tr>

<td align="left" valign="top" width="60%" class="grey_ver11">

<cc2:editor width="600px" height="150px" runat="server" id="TxtResponseOne"></cc2:editor><%


--<custom:CustomEditor id="TxtResponseOne" width="600px" height="150px" runat="server" />--%></td>

<td align="right" class="grey_ver11" valign="top" width="40%">

<div id="ROneCount" class="DefaultTextBoxCounterStyle" runat="server">

</div>

</td>

</tr>

</table>




This jquery is working for Html mode of editior bue not working for ythe design mode of it. do any one have solution.

Answers (5)