Jump to content

Textarea Control


frankieJr
 Share

Recommended Posts

Hey all,I have a script that limit characters and lines entered by users in a textarea..i want instead of throwing that alert message to jump to the next line and the user can continue writing, here is the script:

<script type="text/javascript">var alert_title='Input Restriction';function limitTextarea(el,maxLines,maxChar){	if(!el.x)	{		el.x=uniqueInt();		el.onblur=function(){clearInterval(window['int'+el.x])}	}	window['int'+el.x]=setInterval(function(){		var lines=el.value.replace(/\r/g,'').split('\n'),		i=lines.length,		lines_removed,		char_removed;		if(maxLines&&i>maxLines){			alert('You can not enter\nmore than '+maxLines+' lines');			lines=lines.slice(0,maxLines);			lines_removed=1		}		if(maxChar){			i=lines.length;			while(i-->0)if(lines[i].length>maxChar){				lines[i]=lines[i].slice(0,maxChar);				   char_removed=1			}			if(char_removed)			alert('You can not enter more\nthan '+maxChar+' characters per line')		}		if(char_removed||lines_removed)			el.value=lines.join('\n')		},50);}function uniqueInt(){	var num,maxNum=100000;	if(!uniqueInt.a||maxNum<=uniqueInt.a.length)uniqueInt.a=[];	do num=Math.ceil(Math.random()*maxNum);	while(uniqueInt.a.hasMember(num))	uniqueInt.a[uniqueInt.a.length]=num;	return num}Array.prototype.hasMember=function(testItem){var i=this.length;while(i-->0)if(testItem==this[i])return 1;return 0};</script>

The HTML

<textarea onFocus="limitTextarea(this,5,40)" wrap="soft"></textarea>

please help!

Edited by frankieJr
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...