What counts as an element in a form?

When javascript counts the number of elements in a form, what counts as an element. That is, what does javascript count?

The number of input elements (<li>) varies from 1 - 5. When I changed the input submit src=image button with the <button> submit button, javascript counted one additional element. How can I get it to count just the elements in the <li>? Thanks.

var length = document.form.elements.length;

<form name="form" method="post" enctype="multipart/form-data" >

 <li>
  <input name="checkbox" type="checkbox" value="'. $i . '"/>
 </li>

<!--<input name="submit_checkbox" type="image" src="/images/submit.jpg"/>-->
<button name="submit_checkbox" type="submit">submit</button>

</form>

Open in new window

kadinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
you can use jQuery (which is just javascript in easy to use form)

$("form[name=form] li").length
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobOwner (Aidellio)Commented:
0
kadinAuthor Commented:
Thanks for your response.

I am not using jQuery. Maybe in the future I will look into it, but right now I need a javaScript answer.
Do you think based on your answer I might be able to use?
var count = documentgetelementbyid.theLiElementid.count;
0
kadinAuthor Commented:
Thanks for your help. You got me thinking in the right direction. I used this and it worked.

var length = document.getElementsByName('checkbox').length;
0
RobOwner (Aidellio)Commented:
Sure and glad you got your answer.  the jQuery was doing the same thing behind the scenes.

For future reference have a read of Js frameworks (as they are nothing more than just javascript)
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_12264-Javascript-Frameworks-what-are-they.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.