sms9z
2008-Jan-09 04:16 UTC
Using Prototype - Getting Javascript Error - "Object doesn''t support this property or method"
I have the following javascript being called on my site and I am
getting a Javascript error - "Object doesn''t support this property
or
method". The error is invoked on the line that has - "listItems = $
("vidList").childElements("li");".
The purpose of the Javascript is two fold: ''swapVideo'' to
change the
Youtube video and ''assignB'' to change the bullet for the
<li> from
grey to yellow (yellowdot). This needs to be invoked when the
corresponding link to the list item is clicked up on.
Please help. Would much appreciate any inputs as I have spent a day
trying to everything under the sun without much luck
Thanks
Sharmil
<ul id="vidList">
<li><a href="{youtube link 1}">Text1</a></li>
<li><a href="{youtube link 2}">Text2</a></li>
...
<li><a href="{youtube link 3}">Text3</a></li>
</ul>
<script type="text/javascript">
function swapVideo(thevideo,isDefault){
if(isDefault==true)
{
listItems = $("vidList").childElements("li");
listItems.each
(
function(item)
{
Event.observe($(item).childElements("a")[0], "click",
assignB);
}
)
}
var so = new SWFObject(thevideo, "vidplayer", "<?php if
(is_numeric($width)) echo $width; else echo $dw; ?>", "<?php if
(is_numeric($height)) echo $height; else echo $dh; ?>", "8",
"#000000");
so.addParam("wmode", "transparent");
so.write("videoPlayer");
}
function assignB(o)
{
listItems = $("vidList").childElements("li");
listItems.each
(
function(item)
{
$(item).className =
$(item).className.replace("yellowdot","");
}
)
var eElement = Event.element(o);
eParents=eElement.ancestors();
eParents[0].className += "yellowdot";
}
</script>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Wizz
2008-Jan-09 08:08 UTC
Re: Using Prototype - Getting Javascript Error - "Object doesn''t support this property or method"
// listItems = $("vidList").childElements("li");
the childElements() method doesn''t accept any parameters... you either
user it without the "li":
listItems = $(''vidList'').childElements();
use the select method:
listItems = $(''vidList'').select(''li'');
or use a css-selector:
listItems = $$(''#vidList li'');
That ''should'' solve your problem.
Greetz,
Wizz
On 9 jan, 05:16, sms9z <shar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I have the following javascript being called on my site and I am
> getting a Javascript error - "Object doesn''t support this
property or
> method". The error is invoked on the line that has - "listItems =
$
> ("vidList").childElements("li");".
>
> The purpose of the Javascript is two fold: ''swapVideo'' to
change the
> Youtube video and ''assignB'' to change the bullet for the
<li> from
> grey to yellow (yellowdot). This needs to be invoked when the
> corresponding link to the list item is clicked up on.
>
> Please help. Would much appreciate any inputs as I have spent a day
> trying to everything under the sun without much luck
>
> Thanks
> Sharmil
>
> <ul id="vidList">
> <li><a href="{youtube link
1}">Text1</a></li>
> <li><a href="{youtube link
2}">Text2</a></li>
> ...
> <li><a href="{youtube link
3}">Text3</a></li>
> </ul>
>
> <script type="text/javascript">
> function swapVideo(thevideo,isDefault){
>
> if(isDefault==true)
> {
> listItems =
$("vidList").childElements("li");
> listItems.each
> (
> function(item)
> {
>
Event.observe($(item).childElements("a")[0], "click",
assignB);
> }
> )
> }
>
> var so = new SWFObject(thevideo, "vidplayer",
"<?php if
> (is_numeric($width)) echo $width; else echo $dw; ?>",
"<?php if
> (is_numeric($height)) echo $height; else echo $dh; ?>",
"8",
> "#000000");
> so.addParam("wmode", "transparent");
> so.write("videoPlayer");
>
> }
>
> function assignB(o)
> {
> listItems = $("vidList").childElements("li");
> listItems.each
> (
> function(item)
> {
> $(item).className =
$(item).className.replace("yellowdot","");
> }
> )
>
> var eElement = Event.element(o);
> eParents=eElement.ancestors();
> eParents[0].className += "yellowdot";
>
> }
>
> </script>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Wizz
2008-Jan-09 08:24 UTC
Re: Using Prototype - Getting Javascript Error - "Object doesn''t support this property or method"
Now I looked at your first function, it might be even better to get
the links right away instead of iterating through the listitems first:
if (isDefault==true) {
$$(''#vidList li a'').invoke(''observe'',
''click'', assignB);
}
as you can see it saves a lot of code 8)
Greetz.
On 9 jan, 05:16, sms9z <shar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I have the following javascript being called on my site and I am
> getting a Javascript error - "Object doesn''t support this
property or
> method". The error is invoked on the line that has - "listItems =
$
> ("vidList").childElements("li");".
>
> The purpose of the Javascript is two fold: ''swapVideo'' to
change the
> Youtube video and ''assignB'' to change the bullet for the
<li> from
> grey to yellow (yellowdot). This needs to be invoked when the
> corresponding link to the list item is clicked up on.
>
> Please help. Would much appreciate any inputs as I have spent a day
> trying to everything under the sun without much luck
>
> Thanks
> Sharmil
>
> <ul id="vidList">
> <li><a href="{youtube link
1}">Text1</a></li>
> <li><a href="{youtube link
2}">Text2</a></li>
> ...
> <li><a href="{youtube link
3}">Text3</a></li>
> </ul>
>
> <script type="text/javascript">
> function swapVideo(thevideo,isDefault){
>
> if(isDefault==true)
> {
> listItems =
$("vidList").childElements("li");
> listItems.each
> (
> function(item)
> {
>
Event.observe($(item).childElements("a")[0], "click",
assignB);
> }
> )
> }
>
> var so = new SWFObject(thevideo, "vidplayer",
"<?php if
> (is_numeric($width)) echo $width; else echo $dw; ?>",
"<?php if
> (is_numeric($height)) echo $height; else echo $dh; ?>",
"8",
> "#000000");
> so.addParam("wmode", "transparent");
> so.write("videoPlayer");
>
> }
>
> function assignB(o)
> {
> listItems = $("vidList").childElements("li");
> listItems.each
> (
> function(item)
> {
> $(item).className =
$(item).className.replace("yellowdot","");
> }
> )
>
> var eElement = Event.element(o);
> eParents=eElement.ancestors();
> eParents[0].className += "yellowdot";
>
> }
>
> </script>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Wizz
2008-Jan-09 08:44 UTC
Re: Using Prototype - Getting Javascript Error - "Object doesn''t support this property or method"
I might be looking like a crazy person right (posting 3 times in a
row), but while I was at it I rewrote your other function too.
Prototype has methods and functions for a lot of standard operations,
why not use them if they''re there?
function swapVideo(thevideo,isDefault) {
if(isDefault==true) {
$$(''#vidList li a'').invoke(''observe'',
''click'', function(ev) {
ev.stop();
assignB(this);
});
}
var so = new SWFObject(thevideo, "vidplayer", "<?php if
(is_numeric($width)) echo $width; else echo $dw; ?>", "<?php if
(is_numeric($height)) echo $height; else echo $dh; ?>", "8",
"#000000");
so.addParam("wmode", "transparent");
so.write("videoPlayer");
}
function assignB(el) {
$$(''#vidList
li'').invoke(''removeClassName'',
''yellowdot'');
el.up(''li'').addClassName(''yellowdot'');
}
This might not even be the most optimal way to do it, but it takes a
lot less code then your example.
I advise you to look through the API pages (http://prototypjs.org/api)
to see what kind of functions there to make your life a lot easier.
Greetz,
Wizz
On 9 jan, 09:24, Wizz <woutaw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Now I looked at your first function, it might be even better to get
> the links right away instead of iterating through the listitems first:
>
> if (isDefault==true) {
> $$(''#vidList li a'').invoke(''observe'',
''click'', assignB);
>
> }
>
> as you can see it saves a lot of code 8)
>
> Greetz.
>
> On 9 jan, 05:16, sms9z
<shar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > I have the following javascript being called on my site and I am
> > getting a Javascript error - "Object doesn''t support
this property or
> > method". The error is invoked on the line that has -
"listItems = $
> > ("vidList").childElements("li");".
>
> > The purpose of the Javascript is two fold:
''swapVideo'' to change the
> > Youtube video and ''assignB'' to change the bullet for
the <li> from
> > grey to yellow (yellowdot). This needs to be invoked when the
> > corresponding link to the list item is clicked up on.
>
> > Please help. Would much appreciate any inputs as I have spent a day
> > trying to everything under the sun without much luck
>
> > Thanks
> > Sharmil
>
> > <ul id="vidList">
> > <li><a href="{youtube link
1}">Text1</a></li>
> > <li><a href="{youtube link
2}">Text2</a></li>
> > ...
> > <li><a href="{youtube link
3}">Text3</a></li>
> > </ul>
>
> > <script type="text/javascript">
> > function swapVideo(thevideo,isDefault){
>
> > if(isDefault==true)
> > {
> > listItems =
$("vidList").childElements("li");
> > listItems.each
> > (
> > function(item)
> > {
> >
Event.observe($(item).childElements("a")[0], "click",
assignB);
> > }
> > )
> > }
>
> > var so = new SWFObject(thevideo, "vidplayer",
"<?php if
> > (is_numeric($width)) echo $width; else echo $dw; ?>",
"<?php if
> > (is_numeric($height)) echo $height; else echo $dh; ?>",
"8",
> > "#000000");
> > so.addParam("wmode", "transparent");
> > so.write("videoPlayer");
>
> > }
>
> > function assignB(o)
> > {
> > listItems =
$("vidList").childElements("li");
> > listItems.each
> > (
> > function(item)
> > {
> > $(item).className =
$(item).className.replace("yellowdot","");
> > }
> > )
>
> > var eElement = Event.element(o);
> > eParents=eElement.ancestors();
> > eParents[0].className += "yellowdot";
>
> > }
>
> > </script>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
LexNonScripta
2008-Jan-09 10:35 UTC
Re: Using Prototype - Getting Javascript Error - "Object doesn''t support this property or method"
On Jan 9, 9:44 am, Wizz <woutaw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I might be looking like a crazy person right (posting 3 times in a > row)...No, not a crazy person... Just a caring one :) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---