You could do this a variety of ways, using prototypes $$ method you
could quickly select all form tags.  Alternatively native JS dom has a
quick reference to such a collection, via document.forms.

As a side note, you'll want to point the onload to a reference of your
function, not the result of the execution.  Put in another way,
window.onload should point to your function, such that when it
executes window.onload() its actually calling your function.  When you
execute the method in its assignment, you're actually assigning it
whatever the value of the function's result, in this case it would be
a collection of forms, not ideal.


findForms = function(){

return $$("form");
return $A(document.forms);

}

window.onload = findForms;

On Oct 24, 12:47 pm, solidhex <[EMAIL PROTECTED]> wrote:
> The problem seems to be with how you are trying to run the code on
> page load. If you are trying to use the dom:loaded method, you would
> need to do this:
>
> document.observe("dom:loaded", findForms);
>
> Also, getElementsByClassName is deprecated now in Prototype. You can
> use the CSS selector - $$('form.foo');
>
> Hope that helps!
>
> On Oct 24, 8:21 am, Clifford James <[EMAIL PROTECTED]> wrote:
>
> > I got the following HTML:
>
> > <form id="form1" action="" method="post" class="validate">
> >         <table>
> >                 <tr>
> >                         <td><label for="name" 
> > id="label_name">Naam</label></td>
> >                         <td><input type="text" id="name" name="name" 
> > class="required"/></
> > td>
> >                 </tr>
> >                 <tr>
> >                         <td><label for="email" 
> > id="label_email">Email</label></td>
> >                         <td><input type="text" id="email" name="email" 
> > class="required"/></
> > td>
> >                 </tr>
> >                 <tr>
> >                         <td valign="top"><label for="message" 
> > id="label_message">Bericht</
> > label></td>
> >                         <td><textarea id="message" name="message" rows="4" 
> > cols="20"></
> > textarea></td>
> >                 </tr>
> >                 <tr>
> >                         <td colspan="2" align="right"><input 
> > type="submit"/></td>
> >                 </tr>
> >         </table>
> > </form>
>
> > And the following JavaScript:
> > function findForms()
> > {
> >         var forms = document.getElementsByClassName('validate');
>
> >         // alert returns [object HTMLCollection]
> >         alert(forms);
>
> >         // this isn't working:
> >         for(var i = 0; i < forms.length; i++) alert(forms[i].id);
>
> >         // this isn't working:
> >         forms.each(function(form) { alert(form.id) } )
>
> > }
>
> > document.onload = findForms();
>
> > What is going wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to