views:

21

answers:

2

My document contains more than one forms. How can I get an array of all forms using prototype?

<html>
<head></head>
<body>
 <form id="form1">
  <!-- Other stuffs here -->
 </form>
 <form id="form2">
  <!-- Other stuffs here -->
 </form>
 <form id="form3">
  <!-- Other stuffs here -->
 </form>
</body>
</html>
+1  A: 

You can use the document.forms property.

SLaks
@OP: If you do it this way and want to use any of Prototype's extensions on one of the forms, be sure to run it through `$` first, e.g. NOT `data = document.forms[0].serialize();`, but instead `data = $(document.forms[0]).serialize();` The former will work on Firefox, Chrome, and some others but fail on IE. Whereas that's done for you if you use `$$` (see Dan's answer). Either is totally fine and works well.
T.J. Crowder
+3  A: 

Using prototype:

$$('form')
Dan Heberden