Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: counting number of linebreaks in textfield


Message #1 by "Maurice Faber" <mrdata@i...> on Fri, 16 Nov 2001 13:21:19 +0100
It did Johannes, tnx a lot!

-----Original Message-----
From: johannes [mailto:johannes@p...]
Sent: vrijdag 16 november 2001 15:25
To: javascript
Subject: [javascript] Re: counting number of linebreaks in textfield


Hi Maurice

mabe this helps:

function brCount(objForm)
{
 var arrNewlines = objForm.area1.value.match(/\n/g)
 alert(arrNewlines.length);
}

<form onSubmit="return brCount(this)">
<textarea name="area1"></textarea>
<input type="submit">
</form>


When posting this form it will alert you the number of newlines found in the
textarea.
You can test the arrNewlines.lenght to see the number of newlines in the
field.

kind regards,
johannes


----- Original Message -----
From: "Maurice Faber" <mrdata@i...>
To: "javascript" <javascript@p...>
Sent: Friday, November 16, 2001 13:21
Subject: [javascript] counting number of linebreaks in textfield


> Hello there,
>
> I am trying to validate a textfield that I want to allow to have only 5
> linebreaks.
>
> How is this done?
>
> I have been scripting in PHP too long to remember. Does it have some built
> in count functionality? Or do I append a dummy character to char(13) with
> 'replace' and recount the length of the textfield? I read this somewhere,
> but don't want to implemend it just yet....
>
> Maurice
>
>
>
>
>
>









  Return to Index