Link to home
Start Free TrialLog in
Avatar of Sheldon Livingston
Sheldon LivingstonFlag for United States of America

asked on

How many elements using jquery and php

I have many <input> elements on my webpage.
Is there any way the jquery can tell me how many?

All the <input> elements have the id of theSameIDName.
Avatar of chaau
chaau
Flag of Australia image

You can't have the elements with the same id. Are you sure you have the elements with the same id?
To get the number of the elements use length:
Take this sample:
<input type='text' id='theSameIDName' name='theSameName'>
<input type='text' id='theSameIDName' name='theSameName'>

Open in new window

And the following javascript code:
alert($("[name='theSameName']").length);

Open in new window

alert($("#theSameIDName").length);

Open in new window

The first alert will display 2, but the second one will display 1
Avatar of Sheldon Livingston

ASKER

You most definetalty can have elements with the same name...
ASKER CERTIFIED SOLUTION
Avatar of chaau
chaau
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
jquery needs to be able to count elements... hopefully in a few years.  Lame
jQuery does:

alert($(':input').length);

Open in new window


See here: https://api.jquery.com/input-selector/