Jump to content

Max lines need a popup box


downah

Recommended Posts

Hi guys I have this script here, which counts the characters and lines, now currently though it still allows lines and characters to go into minus, but I would like it to also put up a warning box so it stops the user from being able to put in more text, could you help me out?

 

javascript:

 

function textCounter(theField,theCharCounter,theLineCounter,maxChars,maxLines,maxPerLine)

{

var strTemp = "";

var strLineCounter = 0;

var strCharCounter = 0;



for (var i = 0; i < theField.value.length; i++)

{

	var strChar = theField.value.substring(i, i + 1);



	if (strChar == '\n')

	{

		strTemp += strChar;

		strCharCounter = 1;

		strLineCounter += 1;

	}

	else if (strCharCounter == maxPerLine)

	{

		strTemp += '\n' + strChar;

		strCharCounter = 1;

		strLineCounter += 1;

	}

	else

	{

		strTemp += strChar;

		strCharCounter ++;

	}

}



theCharCounter.value = maxChars - strTemp.length;

theLineCounter.value = maxLines - strLineCounter;

}


 

and used in code:

<textarea name="comment" cols="50" rows="10" wrap="VIRTUAL" onKeyUp="textCounter(theForm.comment,theForm.remChars,remLines,900,30,50);"></textarea>

<br><input name=remChars type=text value="900" size=3 maxlength=3 readonly> characters left

<br><input name=remLines type=text value="30" size=3 maxlength=3 readonly> lines left<br>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.