Jump to content

Maximum input for textarea (table field varchar(300))


kurt.santo

Recommended Posts

I don't think max length works for text areas. Assuming I'm right,I think you'll want an onkeypress handler that counts the chars in the textarea and stops accepting at 300. You'll want an onchange handler in case they paste a bunch more than 300. You'll want to double check the length at submit time. And you'll want to do something serverside for the crackers who break all your clientside security. For the people who don't have javascript and got through all your security by chance, better send back the form with a polite message.A lot of sites have a little char counter beneath the TA so users can see how they're doing. I like that. You'll be examining the value anyway, so you might as well display it.

Link to comment
Share on other sites

I did something like this:

<html>  <head>	<title>sample</title>	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">	<script language="JavaScript">	  function textCounter(field, maxChars, divName)	  {		var txtArea = document.getElementById(field)		var strTemp = "";		for (var i = 0; i < txtArea.value.length; i++)		{		  var strChar = txtArea.value.substring(i, i + 1);		  strTemp += strChar;		}		if (strTemp.length > maxChars)		{		  alert("Please limit your text to " + maxChars + " characters, including letters, numbers and underscores.  Watch the counter to tell how many characters you have remaining.");		  txtArea.value = strTemp.substring(0, maxChars);		}		document.getElementById(divName).innerHTML = "Characters remaining: <b>" + (maxChars - txtArea.value.length) + "</b>";	  }	</script>  </head>  <body>	<textarea class="standard_input" name="new_topic" id="new_topic" rows=2 cols=52 onKeyUp="textCounter('new_topic', 255, 'topic_chars');"></textarea>	<div id="topic_chars" class="fineprint_light" align="right">Characters remaining: <b>255</b></div>  </body></html>

Link to comment
Share on other sites

I did something like this:
<html>  <head>	<title>sample</title>	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">	<script language="JavaScript">	  function textCounter(field, maxChars, divName)	  {		var txtArea = document.getElementById(field)		var strTemp = "";		for (var i = 0; i < txtArea.value.length; i++)		{		  var strChar = txtArea.value.substring(i, i + 1);		  strTemp += strChar;		}		if (strTemp.length > maxChars)		{		  alert("Please limit your text to " + maxChars + " characters, including letters, numbers and underscores.  Watch the counter to tell how many characters you have remaining.");		  txtArea.value = strTemp.substring(0, maxChars);		}		document.getElementById(divName).innerHTML = "Characters remaining: <b>" + (maxChars - txtArea.value.length) + "</b>";	  }	</script>  </head>  <body>	<textarea class="standard_input" name="new_topic" id="new_topic" rows=2 cols=52 onKeyUp="textCounter('new_topic', 255, 'topic_chars');"></textarea>	<div id="topic_chars" class="fineprint_light" align="right">Characters remaining: <b>255</b></div>  </body></html>

Thanks for all inputs. Tested the code and works well.Cheers,KurtBy the way, sorry for late reply. Kind of strange week for me...
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...