Counting Input Boxes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eatspinach
Forum Newbie
Posts: 20
Joined: Mon Apr 20, 2009 8:50 am

Counting Input Boxes

Post by eatspinach »

Hi

I am looking for some code that will count the number of text boxes on my page...


Any Ideas??


Thanks

:D
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Counting Input Boxes

Post by it2051229 »

use javascript...

Code: Select all

 
<script type='text/javascript'>
int textboxesCount = 0;
 
window.onload = function()
{
     var inputTags = document.getElementsByTagName("input");
     
     for(i = 0; i < inputTags.length; i++)
     {
            if(inputTags[i].type == "text")
            {
                           textboxesCount++;
            }
     }
 
    alert("you have " + textboxesCount + " textboxes in your page");
}
 
</script>
 
eatspinach
Forum Newbie
Posts: 20
Joined: Mon Apr 20, 2009 8:50 am

Re: Counting Input Boxes

Post by eatspinach »

Thanks Very Much. That worked.

I had to change the line,

int textboxesCount = 0;

to

var textboxesCount = 0;

before it would work but thats great thanks...

:drunk:
Post Reply