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.

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   10919 Views

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


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

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 :)


Community Member, 902 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
	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.

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 :)