[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 99
  • Last Modified:

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

0
kadin
Asked:
kadin
  • 3
  • 2
1 Solution
 
RobOwner (Aidellio)Commented:
you can use jQuery (which is just javascript in easy to use form)

$("form[name=form] li").length
0
 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now