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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count amount off HTMLTags in a textarea value 1

Status
Not open for further replies.

RayDance

Programmer
Mar 22, 2002
13
0
0
NL
I'm inserting large amounts off text in one textarea and it's HTML text. I use <hr /> for a page break, but now I want to know how many pages I have in one textarea. So I have to know the amount/count off the <hr /> TAGs. Does anybody know how I can count these <hr /> TAGs from the texarea value? Maby something with getElementsByTagName??

Now I have something like this:
* myform.ItemInfo is a textarea

<script>
arrayOfHRs = document.myform.ItemInfo.getElementsByTagName(&quot;hr&quot;);
</script>

But This doesn't work.
If you can help me.... thx!
 
You should do it &quot;manually&quot; in a loop that search for <hr /> substring.
Use this:
if (myform.ItemInfo.value.indexOf(&quot;<hr />&quot;) != -1)
counter ++

 
An easier way out is to do this:
Code:
arrayOfPages=document.myForm.ItemInfo.value.split('<hr />');
alert(arrayOfPages.length)
You won't exactly retain the <hr /> tags, but you'll have a quick and easy way to find the number of pages and reference each one without much difficulty.
Code:
- UNIMENT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top