C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » General »

To restrict textbox length


Posted Date: 31 Aug 2009    Resource Type: Code Snippets    Category: General
Author: RitzMember Level: Silver    
Rating: 1 out of 5Points: 4



Description :


This code shows how to restrict textbox length


<script language="javascript" type="text/javascript">
/*
Set maximum lengthe for textbox using JavaScript with remaining characters
This function is used to validate the textbox for the Maximum lengh
Parameter:
txtBox --> This is the parameter to be passed as a textbox object
maxLength --> This parameter is used to pass the Maximum length of the Textbox
------------------------------------------------------------------------------------
We have to call this function for onkeyup and onkeydown events of the textbox or textArea
*/
function fnClicked(txtBox, maxLength)
{
//Here we are validating the Length of the Text.
//If the text is greater than the provided lenth, we have to ignore the last characters
if(txtBox.value.length >= maxLength)
{
//Removing the last characters which are more than the length
txtBox.value = txtBox.value.substring(0, 160);
}
//Displaying the Remaining characters
document.getElementById('lbl').innerHTML = maxLength - txtBox.value.length;
}
</script>



Responses

Author: Mohan    03 Sep 2009Member Level: Diamond   Points : 1
Nice Snippet..

But already we have one property Maxlength for textbox.

Easily We Assign Maxlength=50


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Textbox length variations  .  Restrict texbox length  .  Length of the textbox  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to clear all the textboxes in your form At Once
Previous Resource: How to create PDF using c# and asp.net
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use