Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-28-2010, 12:26 AM   PM User | #1
javanewbie7
Regular Coder

 
Join Date: Oct 2010
Posts: 121
Thanks: 25
Thanked 0 Times in 0 Posts
javanewbie7 is an unknown quantity at this point
Two Java scripts not working

Hello,

I'm new to java script. I have placed two scripts into my HTML document and only one works. If I take one out, then the other works. What am I doing wrong? The page I'm talking about is mrswaldrop.com/temp2.htm

Thanks for your help.
javanewbie7 is offline   Reply With Quote
Old 10-28-2010, 12:27 AM   PM User | #2
javanewbie7
Regular Coder

 
Join Date: Oct 2010
Posts: 121
Thanks: 25
Thanked 0 Times in 0 Posts
javanewbie7 is an unknown quantity at this point
OK, now it appears that neither is working. I swear it was working earlier
javanewbie7 is offline   Reply With Quote
Old 10-28-2010, 12:49 AM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
No code, no help. There are a few mind readers who occasionally visit this forum, but they're at a conference on Rigel IV this week.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 10-28-2010, 02:40 AM   PM User | #4
javanewbie7
Regular Coder

 
Join Date: Oct 2010
Posts: 121
Thanks: 25
Thanked 0 Times in 0 Posts
javanewbie7 is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
No code, no help. There are a few mind readers who occasionally visit this forum, but they're at a conference on Rigel IV this week.
That's why I posted a link.

Here's the code.
<!-- include jQuery library -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<!-- include Cycle plugin -->
<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.slideshow').cycle({
fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
});
});
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script><script src="temp.js" type="text/javascript"></script>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
javanewbie7 is offline   Reply With Quote
Old 10-28-2010, 02:55 AM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
LOL! Well, I'm old and going senile. And now blind as well. You didn't make it *INTO* a link, so I didn't notice that there was a URL in there. DOH on me.

I don't use jQuery, but I'll take a peek, anyway.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 10-28-2010, 03:01 AM   PM User | #6
javanewbie7
Regular Coder

 
Join Date: Oct 2010
Posts: 121
Thanks: 25
Thanked 0 Times in 0 Posts
javanewbie7 is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
LOL! Well, I'm old and going senile. And now blind as well. You didn't make it *INTO* a link, so I didn't notice that there was a URL in there. DOH on me.

I don't use jQuery, but I'll take a peek, anyway.
No problem, I should have linked it. Besides, I meant to put the winking smilie to let you know I was joking around.

Anyway, thanks for taking a peak.
javanewbie7 is offline   Reply With Quote
Old 10-28-2010, 03:01 AM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Bring it up in Firefox. Enable Firebug debugging. Hit refresh.

WHAM.

Error: $(".slideshow").cycle is not a function

Since pretty clearly there is a cycle() function in that JS code, I'd have to guess that the problem is that $(".slideshow") isn't selecting an element or is maybe selecting more than one element.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 10-28-2010, 03:05 AM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Well, so much for that theory. I see the <div class="slideshow"> and there's only one of them.

I noticed that cycle( ) was defined as $.fn.cycle so maybe there is indeed a conflict in the definition of fn. Anyway, sorry, not a jQuery user, as I said.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 10-28-2010, 03:38 AM   PM User | #9
low tech
Regular Coder

 
low tech's Avatar
 
Join Date: Dec 2009
Posts: 740
Thanks: 149
Thanked 67 Times in 67 Posts
low tech is on a distinguished road
Hi

I'm no Jquery person but I think you are ref a class instead of an ID

"The plugin provides a method called cycle which is invoked on a container element. Each child element of the container becomes a "slide". Options control how and when the slides are transitioned."

I think is wrong
Code:
$('.slideshow').cycle
I think it sould ref ID
Code:
example only
$('#s1').cycle('fade')
for ref:
http://malsup.com/jquery/cycle/begin.html

http://malsup.com/jquery/cycle/

also I think you have this twice
Code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript">
I would get rid of the second one
LT

Last edited by low tech; 10-28-2010 at 03:51 AM..
low tech is offline   Reply With Quote
Old 10-28-2010, 07:54 AM   PM User | #10
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
No, that much of jQuery I know.

You can refer to elements *EITHER* by class name or by id.

The "." prefix means class name, the "#" prefix means id. Same as in CSS.

Now, you *can* get in trouble using class name. If you use a $(".xxx") selector and you have more than one object of the classname, jQuery will try to apply the property/method/whatever to *all* those objects. And clearly there some functions where that's not going to work.

But in this case, I see only a single object of that class, and so it should work.

Personally, I would *NEVER* try to select a single object using class name, just because of the danger that you might accidentally be selecting more than one.

But jQuery says its legal, even if inadvisable.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 10-28-2010, 01:57 PM   PM User | #11
low tech
Regular Coder

 
low tech's Avatar
 
Join Date: Dec 2009
Posts: 740
Thanks: 149
Thanked 67 Times in 67 Posts
low tech is on a distinguished road
Hi Old Pedant

Thanks for putting me right:-)

Yeh @ #7 I saw that you wrote "maybe selecting more than one element"

so I thought he was using class name and so possibly it was causing problem --- when I ref the jquery site I saw they used an ID $('#s1') and I've used this same cycle plugin myself with an id and it worked fine. Hence my suggestion.

Anyway I learned what the problem isn't:-)

sorry to javanewbie7.
LT
low tech is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:47 AM.


Advertisement
Log in to turn off these ads.