Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

jQuery function not defined


Go to End


3 Posts   12565 Views

Avatar
Carbon Crayon

Community Member, 598 Posts

16 May 2009 at 7:39am

Hi Guys

I'm having a little trouble getting this jquery to run through SS. firebug reports that:

slideSwitch is not defined
[Break on this error] setInterval( "slideSwitch()", 500 );

here is the code that I have in a file jquery.slide.show.js

(function($){

		function slideSwitch() {
                      //Some Stuff
		}
		
		$j(document).ready(function() {
		    setInterval( "slideSwitch()", 500 );
		});
	
})
(jQuery);

this works fine in a static HTML file, but as soon as I pass it through SS it breaks.

Anyone know what I'm doing wrong?

Cheers :)

Avatar
bummzack

Community Member, 904 Posts

16 May 2009 at 8:50pm

Hi aram

Are you placing this in the jQuery "scope" on purpose? You're not extending $.fn or anything...
I also wonder where that $j is coming from (see $j(document).ready in your code snippet)?

I suggest you try something like this:

var $j = jQuery.noConflict();

var slideSwitch = function(){
	... somestuff...
};

// the following does the same as $(document).ready
$j(function(){
	window.setInterval(slideSwitch, 500);
});

Writing code like this has proven to work with SilverStripe (at least for me). And since you're not actually extending the jQuery functionality, there's no need to place your functions in the jQuery scope.

Avatar
Carbon Crayon

Community Member, 598 Posts

16 May 2009 at 10:25pm

Thanks banal, that did the trick!

I had misunderstood the use of the scope, I though that was needed for some reason.

Thanks again :)