C# Tutorials and offshore development in India
Tutorials Resources Forum Reviews Communities Interview Jobs Projects Training Videos


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...


Birthday Greetings
Learn Windows 7: How to download videos from top video streaming sites   This article explains how to download the video files from various video hosting sites like YouTube, Google, DailyMotion, Yahoo and many more in online without downloading any software's



Resources » Code Snippets » General »

To restrict textbox length


Posted Date: 31 Aug 2009    Resource Type: Code Snippets    Category: General
Author: RituMember Level: Gold    
Rating: 1 out of 5Points: 4 (Rs 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 to the resource: "To restrict textbox length"
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.
Restrict texbox length  .  Length of the textbox  .  Textbox length variations  .  

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 Resources
Post New Resource
Category: General


Post resources and earn money!
 
More Resources



About Us    Contact Us    Privacy Policy    Terms Of Use