Friday, October 29, 2010

Multi Line Text Box Validation


function textCounter_Multi(field, maxlimit) {
/*
* The input parameters are: the field name;
* field that holds the number of characters remaining;
* the max. numb. of characters.
*/
countfield = document.getElementById('myspan');
//alert(countfield);
if (field.value.length > maxlimit) // if the current length is more than allowed
field.value = field.value.substring(0, maxlimit); // don't allow further input
else
countfield.innerHTML = maxlimit - field.value.length;
} // set the display field to remaining number



call this function at text box where you are using

onkeydown="textCounter_Multi(this, 150);"
onkeyup="textCounter_Multi(this,150); "
span-- span class="SpanText">(Max. 150 Characters)

span---- id="myspan" class="SpanText">150
Characters left

No comments: