Controlling of Text area Using JavaScript function - CsharpMagic.com

Controlling of Text area Using JavaScript function

just create a function according to the requirements as like-

function countDown(control, maxLen, counter, typeName) {
var len = control.value.length;
var txt = control.value;
var span = document.getElementById(counter);
span.style.display = ”;
span.innerHTML = (maxLen – len) + ‘ characters remaining’;
if (len >= (maxLen – 10)) {
span.style.color = ‘red’;
if (len > maxLen) {
control.innerHTML = txt.substring(0, maxLen);
span.innerHTML = (maxLen – control.value.length) + ‘ characters remaining’;
alert(typeName + ‘ text exceeds the maximum allowed!’);
}
} else {
span.style.color = ”;
}
}
Add This Code in The .aspx file of the .net Programms

<%–

–%>

Description: TextBox onpaste=”countDown(this, 450, ‘desc’, ‘Description’);” id=”Description” onkeypress=”countDown(this, 450, ‘desc’, ‘Description’);” Wrap=”true” onkeyup=”countDown(this, 450, ‘desc’, ‘Description’);”
runat=”server” TextMode=”MultiLine”>
450  characters remaining

<%–

–%>

now Execute and Check…

it will work good
Thanks

Anand Kumar
@anandkumarv

Anand Kumar

Sr.Tech Lead at CsharpMagic
I am founder of csharpmagic.com and by profession Sr.Tech Lead. I like to explore New Technologies, New Business idea and many more
Anand Kumar
@anandkumarv

Anand Kumar

I am founder of csharpmagic.com and by profession Sr.Tech Lead. I like to explore New Technologies, New Business idea and many more

Leave a Reply

Your email address will not be published. Required fields are marked *