Tuesday, February 9, 2010

How to control the data in text area using ASP.NET and Java Script


First Create a java script as given below
====================================================
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…
Thanks

No comments:

Post a Comment