[Javascript] Maxlength on textarea in XHTML
Mike Dougherty
mdougherty at pbp.com
Thu Apr 14 11:41:41 CDT 2005
what error are you getting?
x[i].onkeypress = checkLength(x);
function checkLength()
it looks like you are passing X to a function that does not accept parameters...
On Thu, 14 Apr 2005 09:14:49 -0700
Charles Stuart <about-css at enure.net> wrote:
>Hello All,
>
>I need to set a maxlength on all of the textarea's on a site. I am using XHTML 1.0 transitional.
>I've tried without success to implement Peter-Paul Koch's code located here:
>http://www.alistapart.com/authors/peterpaulkoch/
>
>My needs are simpler than what is presented on A List Apart. The maxlength will always be the
>same value. And, don't mind having
> onkeypress="checkLength()"
>in the XHTML.
>
>So far I have this:
>
>var x = document.getElementsByTagName('textarea');
>for (var i=0;i<x.length;i++)
>{
> x[i].onkeypress = checkLength(x);
>}
>
>function checkLength()
>{
> var howMany = document.getElementsByTagName('textarea');
> var max = 30;
>
> if (howMany.length > max)
> {
> window.alert("You can only type 30 characters");
> }
>}
>
>
>My second attempt was this:
>
>
>function checkLength()
>{
> event = window.event;
> element = event.srcElement;
> var howMany = document.forms[0].element.length;
>
> if (howMany.length > 30)
>{
> window.alert("You can only type 300 characters");
>}
>}
>
>
>
>Thank you for any help. Let me know if I should put an example up.
>
>
>
>best,
>
>Charles
>
>
>
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
>
>__________________________________________________________
>This message was scanned by ATX
>12:32:43 PM ET - 4/14/2005
More information about the Javascript
mailing list