Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Safari and TextArea Events



Hi Robert,


I have found this problem in the past with Safari.  I coded round it with
the following javascript, using the onkeyup event which is fired after the
key is added to the textarea.  This approach should work in all browsers
that support key events.

It also allows the user to edit the textarea contents once the limit has
been reached - it will accept the delete key, and it will allow selected
text to be replaced.


<script language="javascript">

function limitLength(obj,length)
{
  if(!obj.prevValue)
  {
    obj.prevValue=obj.value;
  }
  else if(obj.prevValue!=obj.value)
  {
    if(obj.prevValue.length < obj.value.length)
    {
      if(obj.value.length>length)
      {
        obj.value=obj.prevValue;
      }
    }

    obj.prevValue=obj.value;
  }
}

</script>



<textarea id="MyTextArea" onkeyup="limitLength(this,39);"></textarea>



Regards,

John Jameson
_______________________________________________
web-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/web-development
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.