I could really use some help with the proper syntax to access the values returned by getElementsByClassName (and similar functions): My HTML code includes several forms with a specific class: <form class="nmd_upload_iframetype" id="file_upload_8" ...> etc... </form> I''ve included prototype.js, and am running the following code: var formarray document.getElementsByClassName(''nmd_upload_iframetype''); var count = form.length; document.write(count); This code prints ''0'' Any advice will be appreciated. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Bastian Feder
2007-Aug-03 07:09 UTC
Re: Need help accessing result of getElementsByClassName
Hey Saiena, you are using different variables for teh array og elements and for the count. Make it: var count = formarray.length; this should do ;o) But in your case .. why don''t you us $A ?? e.g: var count = $A(document.getElementsByClassName (''nmd_upload_iframetype'')).length; hf Bastian On 8/3/07, saiena <saiena-9LViYcISHtsZtaGS8SxrTBZCeNDtXRbv@public.gmane.org> wrote:> > > I could really use some help with the proper syntax to access the > values returned by > getElementsByClassName (and similar functions): > > My HTML code includes several forms with a specific class: > <form class="nmd_upload_iframetype" id="file_upload_8" ...> > etc... > </form> > > I''ve included prototype.js, and am running the following code: > > var formarray > document.getElementsByClassName(''nmd_upload_iframetype''); > var count = form.length; > document.write(count); > This code prints ''0'' > > Any advice will be appreciated. > > > > >-- -- spread the word ... see www.browsehappy.com ;o) Calvin: Weekends don''t count unless you spend them doing something completely pointless. Join the Greater IBM Connection ( http://www.xing.com/premiumgroup-6291.d26b7d) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for your reply. The unassigned variable was just an error ai made when posting to the group. Thanks for the tip on using the $A. I can now get the funciton to work under some conditions, e.g., on a mousedown event. The problem is that it won''t work on a window load. in the code below, clicking the "CLICK ME" link corretly return ''2'' as the count. But the onload event always reports ''0''. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script src="/includes/prototype.js" type="text/javascript"></ script> <script language="JavaScript" type="text/JavaScript"> function uploadframes(){ var count $A(document.getElementsByClassName(''nmd_upload_iframetype'')).length; document.write(count); } window.onload=uploadframes(); </script> </head> <body> <a href="" onMouseDown="uploadframes()">CLICK ME</a> <table class="bealle" width="758" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td valign="top"> <form class="nmd_upload_iframetype" nmdformtype="fileupload" id="file_upload_8" method="post" enctype="multipart/form-data" action="/nmd_modules.php?mod=upload&assetpath=%2Fassets%2Fphotos %2F&filetype=img&forcewidth=300&forceheight="> FORM CONTROLS HERE </form> </td> </tr> <tr> <td valign="top"> <form class="nmd_upload_iframetype" nmdformtype="fileupload" id="file_upload_9" method="post" enctype="multipart/form-data" action="/nmd_modules.php?mod=upload&assetpath=%2Fassets%2Fphotos %2F&filetype=img&forcewidth=300&forceheight="> FORM CONTROLS HERE </form> </td> </tr> </table> </body> </html> On Aug 3, 12:09 am, "Bastian Feder" <bastian.fe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey Saiena, > > you are using different variables for teh array og elements and for the > count. > > Make it: > var count = formarray.length; > > this should do ;o) > > But in your case .. why don''t you us $A ?? > > e.g: > var count = $A(document.getElementsByClassName > (''nmd_upload_iframetype'')).length; > > hf > Bastian > > On 8/3/07, saiena <sai...-9LViYcISHtsZtaGS8SxrTBZCeNDtXRbv@public.gmane.org> wrote: > > > > > > > > > I could really use some help with the proper syntax to access the > > values returned by > > getElementsByClassName (and similar functions): > > > My HTML code includes several forms with a specific class: > > <form class="nmd_upload_iframetype" id="file_upload_8" ...> > > etc... > > </form> > > > I''ve included prototype.js, and am running the following code: > > > var formarray > > document.getElementsByClassName(''nmd_upload_iframetype''); > > var count = form.length; > > document.write(count); > > This code prints ''0'' > > > Any advice will be appreciated. > > -- > -- > spread the word ... seewww.browsehappy.com;o) > > Calvin: Weekends don''t count unless you spend them doing something > completely pointless. > > Join the Greater IBM Connection (http://www.xing.com/premiumgroup-6291.d26b7d)- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Got it, now. I had to put the window.onload function in a script tag at the very end of the body rathe rthan in the head. -saiena On Aug 3, 9:31 am, saiena <sai...-9LViYcISHtsZtaGS8SxrTBZCeNDtXRbv@public.gmane.org> wrote:> Thanks for your reply. The unassigned variable was just an error ai > made when posting to the group. Thanks for the tip on using the $A. I > can now get the funciton to work under some conditions, e.g., on a > mousedown event. The problem is that it won''t work on a window load. > in the code below, clicking the "CLICK ME" link corretly return ''2'' as > the count. But the onload event always reports ''0''. > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > <meta http-equiv="Content-Type" content="text/html; > charset=iso-8859-1"> > <script src="/includes/prototype.js" type="text/javascript"></ > script> > <script language="JavaScript" type="text/JavaScript"> > function uploadframes(){ > var count > $A(document.getElementsByClassName(''nmd_upload_iframetype'')).length; > document.write(count); > } > window.onload=uploadframes(); > </script> > > </head> > <body> > <a href="" onMouseDown="uploadframes()">CLICK ME</a> > > <table class="bealle" width="758" border="0" cellspacing="0" > cellpadding="0" align="center"> > <tr> > <td valign="top"> > <form class="nmd_upload_iframetype" nmdformtype="fileupload" > id="file_upload_8" method="post" enctype="multipart/form-data" > action="/nmd_modules.php?mod=upload&assetpath=%2Fassets%2Fphotos > %2F&filetype=img&forcewidth=300&forceheight="> > FORM CONTROLS HERE > </form> > </td> > </tr> > <tr> > <td valign="top"> > <form class="nmd_upload_iframetype" nmdformtype="fileupload" > id="file_upload_9" method="post" enctype="multipart/form-data" > action="/nmd_modules.php?mod=upload&assetpath=%2Fassets%2Fphotos > %2F&filetype=img&forcewidth=300&forceheight="> > FORM CONTROLS HERE > </form> > </td> > </tr> > </table> > </body> > </html> > > On Aug 3, 12:09 am, "Bastian Feder" <bastian.fe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hey Saiena, > > > you are using different variables for teh array og elements and for the > > count. > > > Make it: > > var count = formarray.length; > > > this should do ;o) > > > But in your case .. why don''t you us $A ?? > > > e.g: > > var count = $A(document.getElementsByClassName > > (''nmd_upload_iframetype'')).length; > > > hf > > Bastian > > > On 8/3/07, saiena <sai...-9LViYcISHtsZtaGS8SxrTBZCeNDtXRbv@public.gmane.org> wrote: > > > > I could really use some help with the proper syntax to access the > > > values returned by > > > getElementsByClassName (and similar functions): > > > > My HTML code includes several forms with a specific class: > > > <form class="nmd_upload_iframetype" id="file_upload_8" ...> > > > etc... > > > </form> > > > > I''ve included prototype.js, and am running the following code: > > > > var formarray > > > document.getElementsByClassName(''nmd_upload_iframetype''); > > > var count = form.length; > > > document.write(count); > > > This code prints ''0'' > > > > Any advice will be appreciated. > > > -- > > -- > > spread the word ... seewww.browsehappy.com;o) > > > Calvin: Weekends don''t count unless you spend them doing something > > completely pointless. > > > Join the Greater IBM Connection (http://www.xing.com/premiumgroup-6291.d26b7d)-Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Tom Gregory
2007-Aug-04 01:21 UTC
Re: Need help accessing result of getElementsByClassName
You''re still not calling it "onload", you''re calling it when it''s encountered. It''s because you were assigning the function result, not the function reference. Had you done window.onload = uploadFrames; // <-- Assign function reference, no parenthesis you would have been fine. Instead, you were assigning the return value of calling the function to window.onload. window.onload = uploadFrames(); // <-- Incorrect for what you want; Assigning return value TAG On Aug 3, 2007, at 4:46 PM, saiena wrote:> > Got it, now. > > I had to put the window.onload function in a script tag at the very > end of the body rathe rthan in the head. > > -saiena > > > > On Aug 3, 9:31 am, saiena <sai...-9LViYcISHtsZtaGS8SxrTBZCeNDtXRbv@public.gmane.org> wrote: >> Thanks for your reply. The unassigned variable was just an error ai >> made when posting to the group. Thanks for the tip on using the $A. I >> can now get the funciton to work under some conditions, e.g., on a >> mousedown event. The problem is that it won''t work on a window load. >> in the code below, clicking the "CLICK ME" link corretly return >> ''2'' as >> the count. But the onload event always reports ''0''. >> >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> >> <html xmlns="http://www.w3.org/1999/xhtml"> >> <head> >> <meta http-equiv="Content-Type" content="text/html; >> charset=iso-8859-1"> >> <script src="/includes/prototype.js" type="text/javascript"></ >> script> >> <script language="JavaScript" type="text/JavaScript"> >> function uploadframes(){ >> var count >> $A(document.getElementsByClassName(''nmd_upload_iframetype'')).length; >> document.write(count); >> } >> window.onload=uploadframes(); >> </script> >> >> </head> >> <body> >> <a href="" onMouseDown="uploadframes()">CLICK ME</a> >> >> <table class="bealle" width="758" border="0" cellspacing="0" >> cellpadding="0" align="center"> >> <tr> >> <td valign="top"> >> <form class="nmd_upload_iframetype" nmdformtype="fileupload" >> id="file_upload_8" method="post" enctype="multipart/form-data" >> action="/nmd_modules.php?mod=upload&assetpath=%2Fassets%2Fphotos >> %2F&filetype=img&forcewidth=300&forceheight="> >> FORM CONTROLS HERE >> </form> >> </td> >> </tr> >> <tr> >> <td valign="top"> >> <form class="nmd_upload_iframetype" nmdformtype="fileupload" >> id="file_upload_9" method="post" enctype="multipart/form-data" >> action="/nmd_modules.php?mod=upload&assetpath=%2Fassets%2Fphotos >> %2F&filetype=img&forcewidth=300&forceheight="> >> FORM CONTROLS HERE >> </form> >> </td> >> </tr> >> </table> >> </body> >> </html> >> >> On Aug 3, 12:09 am, "Bastian Feder" <bastian.fe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> >>> Hey Saiena, >> >>> you are using different variables for teh array og elements and >>> for the >>> count. >> >>> Make it: >>> var count = formarray.length; >> >>> this should do ;o) >> >>> But in your case .. why don''t you us $A ?? >> >>> e.g: >>> var count = $A(document.getElementsByClassName >>> (''nmd_upload_iframetype'')).length; >> >>> hf >>> Bastian >> >>> On 8/3/07, saiena <sai...-9LViYcISHtsZtaGS8SxrTBZCeNDtXRbv@public.gmane.org> wrote: >> >>>> I could really use some help with the proper syntax to access the >>>> values returned by >>>> getElementsByClassName (and similar functions): >> >>>> My HTML code includes several forms with a specific class: >>>> <form class="nmd_upload_iframetype" id="file_upload_8" ...> >>>> etc... >>>> </form> >> >>>> I''ve included prototype.js, and am running the following code: >> >>>> var formarray >>>> document.getElementsByClassName(''nmd_upload_iframetype''); >>>> var count = form.length; >>>> document.write(count); >>>> This code prints ''0'' >> >>>> Any advice will be appreciated. >> >>> -- >>> -- >>> spread the word ... seewww.browsehappy.com;o) >> >>> Calvin: Weekends don''t count unless you spend them doing something >>> completely pointless. >> >>> Join the Greater IBM Connection (http://www.xing.com/ >>> premiumgroup-6291.d26b7d)-Hide quoted text - >> >>> - Show quoted text -- Hide quoted text - >> >> - Show quoted text - > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Ah. I see. Thank you! This client-side scripting is new to me... On Aug 3, 6:21 pm, Tom Gregory <t...-PGZyUNKar/Q@public.gmane.org> wrote:> You''re still not calling it "onload", you''re calling it when it''s > encountered. It''s because you were assigning the function result, not > the function reference. > > Had you done > window.onload = uploadFrames; // <-- Assign function reference, no > parenthesis > you would have been fine. > > Instead, you were assigning the return value of calling the function > to window.onload. > window.onload = uploadFrames(); // <-- Incorrect for what you want; > Assigning return value > > TAG > > On Aug 3, 2007, at 4:46 PM, saiena wrote: > > > > > > > Got it, now. > > > I had to put the window.onload function in a script tag at the very > > end of the body rathe rthan in the head. > > > -saiena > > > On Aug 3, 9:31 am, saiena <sai...-9LViYcISHtsZtaGS8SxrTBZCeNDtXRbv@public.gmane.org> wrote: > >> Thanks for your reply. The unassigned variable was just an error ai > >> made when posting to the group. Thanks for the tip on using the $A. I > >> can now get the funciton to work under some conditions, e.g., on a > >> mousedown event. The problem is that it won''t work on a window load. > >> in the code below, clicking the "CLICK ME" link corretly return > >> ''2'' as > >> the count. But the onload event always reports ''0''. > > >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > >> <html xmlns="http://www.w3.org/1999/xhtml"> > >> <head> > >> <meta http-equiv="Content-Type" content="text/html; > >> charset=iso-8859-1"> > >> <script src="/includes/prototype.js" type="text/javascript"></ > >> script> > >> <script language="JavaScript" type="text/JavaScript"> > >> function uploadframes(){ > >> var count > >> $A(document.getElementsByClassName(''nmd_upload_iframetype'')).length; > >> document.write(count); > >> } > >> window.onload=uploadframes(); > >> </script> > > >> </head> > >> <body> > >> <a href="" onMouseDown="uploadframes()">CLICK ME</a> > > >> <table class="bealle" width="758" border="0" cellspacing="0" > >> cellpadding="0" align="center"> > >> <tr> > >> <td valign="top"> > >> <form class="nmd_upload_iframetype" nmdformtype="fileupload" > >> id="file_upload_8" method="post" enctype="multipart/form-data" > >> action="/nmd_modules.php?mod=upload&assetpath=%2Fassets%2Fphotos > >> %2F&filetype=img&forcewidth=300&forceheight="> > >> FORM CONTROLS HERE > >> </form> > >> </td> > >> </tr> > >> <tr> > >> <td valign="top"> > >> <form class="nmd_upload_iframetype" nmdformtype="fileupload" > >> id="file_upload_9" method="post" enctype="multipart/form-data" > >> action="/nmd_modules.php?mod=upload&assetpath=%2Fassets%2Fphotos > >> %2F&filetype=img&forcewidth=300&forceheight="> > >> FORM CONTROLS HERE > >> </form> > >> </td> > >> </tr> > >> </table> > >> </body> > >> </html> > > >> On Aug 3, 12:09 am, "Bastian Feder" <bastian.fe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>> Hey Saiena, > > >>> you are using different variables for teh array og elements and > >>> for the > >>> count. > > >>> Make it: > >>> var count = formarray.length; > > >>> this should do ;o) > > >>> But in your case .. why don''t you us $A ?? > > >>> e.g: > >>> var count = $A(document.getElementsByClassName > >>> (''nmd_upload_iframetype'')).length; > > >>> hf > >>> Bastian > > >>> On 8/3/07, saiena <sai...-9LViYcISHtsZtaGS8SxrTBZCeNDtXRbv@public.gmane.org> wrote: > > >>>> I could really use some help with the proper syntax to access the > >>>> values returned by > >>>> getElementsByClassName (and similar functions): > > >>>> My HTML code includes several forms with a specific class: > >>>> <form class="nmd_upload_iframetype" id="file_upload_8" ...> > >>>> etc... > >>>> </form> > > >>>> I''ve included prototype.js, and am running the following code: > > >>>> var formarray > >>>> document.getElementsByClassName(''nmd_upload_iframetype''); > >>>> var count = form.length; > >>>> document.write(count); > >>>> This code prints ''0'' > > >>>> Any advice will be appreciated. > > >>> -- > >>> -- > >>> spread the word ... seewww.browsehappy.com;o) > > >>> Calvin: Weekends don''t count unless you spend them doing something > >>> completely pointless. > > >>> Join the Greater IBM Connection (http://www.xing.com/ > >>> premiumgroup-6291.d26b7d)-Hide quoted text - > > >>> - Show quoted text -- Hide quoted text - > > >> - Show quoted text -- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---