Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AOL Mac textarea with javascript = no letters, just carats

Status
Not open for further replies.

SauerC

Technical User
Joined
Apr 10, 2001
Messages
47
Location
US
Good Morning All,

Below is the simplified output from an ASP that creates a form for the user to fill out. As you can see, we have a textarea for them to put comments in. We want to limit the size of the comments to 1500 characters. I created four javascript functions so I can check a couple different ways as to whether they put in more data than we want. This works for all Browser/OS combinations EXCEPT AOL's browser on a Mac. When they try to type in the textarea, all they get is a carat symbol ("^") for each letter they type.

Any ideas on why this happens?

-Christian


Code:
<html>
<head>
<script language=&quot;Javascript&quot;>
var sizeLimit = 1500;

function check(e)
{
 var scanCode;
 var target;

 if (document.all)
 {
  e = window.event;
  scanCode = e.keyCode;
  target = e.srcElement;				
 }
 else
 {	
  scanCode = e.which;
  target = e.target;
 }

 if ((scanCode <= 31) || (scanCode >= 127))
  return true;
 else
 {
  if (target.value.length >= sizeLimit)
   return false;
  else
   return true;
 }
}
	
function pastecheck(e)
{
 var scanCode;
 var target;
 var userPaste = false;
		
 if (document.all)
 {
  e = window.event;
  scanCode = e.keyCode;
  target = e.srcElement;

  if ((e.ctrlKey == true) && (scanCode == 86))
   userPaste = true;
 }
 else
 {
  scanCode = e.which;
  target = e.target;
	
  if (scanCode == 22)
  userPaste = true;
 }
		
 if (userPaste == false)
  return true;
 else
 {
  if (target.value.length > sizeLimit)
  {
   alert('You pasted too much text into the textbox...truncated to proper length.');
   target.value = target.value.substr(0, sizeLimit);
  }
 }
}
	
function lostfocus(e)
{
 var target
		
 if (document.all)
 {
  e = window.event;
  target = e.srcElement;
 }
 else
 {
  target = e.target;
 }
	
 if (target.value.length > sizeLimit)
 {
  alert('You pasted too much text into the textbox...trancated to proper length.');
  target.value = target.value.substr(0, sizeLimit);
 }
}
</script>
</head>
<body>
<form name=&quot;EntryForm&quot;>
<textarea cols=&quot;60&quot; rows=&quot;5&quot; name=&quot;Comments1&quot;></textarea>
<script language=&quot;javascript&quot;>
document.EntryForm.Comments1.onkeypress = check;
document.EntryForm.Comments1.onkeyup = pastecheck;
document.EntryForm.Comments1.onblur = lostfocus;
document.EntryForm.Comments1.onchange = lostfocus;
</script>
</form>
</body>
<html>
 
I use one very simple script for limiting textarea size :

<textarea onkeypress=&quot;return (this.value.length < 1500)&quot;></textarea>

Most people understand that they can't type more than 1500 characters this way but for usability tell people to keep it under 1500 characters by saying it in small font on top of the textarea.

I hope this works in your mac version as well. Let me know! :) Gary Haran
 
if you take

Code:
<textarea onkeypress=&quot;return (this.value.length < 10)&quot;></textarea>

and copy in 20 characters of text (either by right clicking in the textarea and selecting &quot;Paste&quot; or by typeing ctrl-v) it will allow the 20 characters to be entered and not stop it at 10.

I'm dealing with magazine editors here who frequently will type out comments and whatnot in their favorite word processor and then just copy and paste the text into the comment field ... hence why I went what seems to be the &quot;round a bout&quot; way.

-Christian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top