Page 1 of 1

Javascript Error. window.addEvent is not a function?

Posted: Wed Mar 09, 2011 5:05 pm
by Siege21
Hi there.

I've been working on a site for a client and this little error message has reared it's head and I can't seem to pinpoint it's cause;

Code: Select all

window.addEvent is not a function

window.addEvent('domready', function(){ setlayout(); }); 
That is pretty much all Firebug will tell me. So far the only thing it's causing problems for is a popup system message that I believe is built into the template. I didn't have any involvement with the template and inital setup, so I'm going in blind here. My Javascript is poor at best too, so any help with this would be greatly appreicated!

I've done a lot of digging and the only solutions to problems similar to this I found were to change "domready" to "load", but that only seemed relevant in IE, and besides, it did nothing when I tried it anyway.

Can anyone help me out?

Thank you in advance! :)

Re: Javascript Error. window.addEvent is not a function?

Posted: Thu Mar 10, 2011 3:13 pm
by jvezina
You're calling window.AddEvent() before the mootools library is loaded.

Re: Javascript Error. window.addEvent is not a function?

Posted: Thu Mar 10, 2011 3:53 pm
by Siege21
*self facepalm*

Thank you! It's all sorted now. :)

Re: Javascript Error. window.addEvent is not a function?

Posted: Thu Mar 10, 2011 4:36 pm
by jvezina
hey, I know what you're going through. I was using mootools with another framework. The framework was nice enough to be inconsistent on when it'd load my files. So on most pages everything worked fine, but then there were the other pages when things got rearranged.

Re: Javascript Error. window.addEvent is not a function?

Posted: Thu Mar 10, 2011 4:53 pm
by Siege21
It is frustrating. The developer used an obscure template framework which just seems to clash at every opportunity with the Joomla core. It's so bad I almost recommended I just re-build the whole site!!

Thanks again for your help.

Re: Javascript Error. window.addEvent is not a function?

Posted: Mon Mar 14, 2011 8:46 am
by sons
Hi,

I am newbie at this. Can somebody, please, explain me what to do to solve this problem?

Thanks in advance!

Re: Javascript Error. window.addEvent is not a function?

Posted: Mon Mar 14, 2011 1:13 pm
by jvezina
Sorry to hear that. Sometimes it's hard to know when to stop throwing good money (& time) after bad.

And for sons, the mootools.js library needs to be loaded before the addEvent() function is called.

Re: Javascript Error. window.addEvent is not a function?

Posted: Mon Mar 14, 2011 1:19 pm
by sons
Hi,
Where to set that? In what file or ...

Thanks

Re: Javascript Error. window.addEvent is not a function?

Posted: Mon Mar 14, 2011 2:14 pm
by jvezina
The problem could actually be from anywhere, but the first place to check is the index.php file of your template.

Another good thing to do is look at the page source of your site to see what's calling the AddEvent function before mootools.js gets loaded (& joomla automatically includes mootools).

Re: Javascript Error. window.addEvent is not a function?

Posted: Mon Jul 25, 2011 3:23 pm
by Nibinaear
I too am getting this problem on a custom template. As far as I can tell Joomla loads mootools anyway if it needs it so I don't know what to do. I'm trying to use ckforms module and the validation won't load. The code is as follows:

Code: Select all

window.addEvent('domready', function(){
	var myTips = new Tips('.ckform_tooltip2', {
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 250, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});


	var myForm = new FormCheck('ckform2', {
		fieldErrorClass : 'error',
		validateDisabled : true,
		display : {
			showErrors : 1,
			errorsLocation : 3,
			indicateErrors : 2,
			tipsPosition : 'right', 
			addClassErrorToField : true,
			scrollToFirst : true
		},
		alerts : {
			required:'This field is required.',
			number:'Please enter a valid number.',
			email:'Please enter a valid email: <br /><span>E.g. yourname&#64;domain.com</span>',
			url:'Please enter a valid url: <br /><span>E.g. http://www.domain.com</span>',
			confirm:'This field is different from %0',
			length_str:'The length is incorrect, it must be between %0 and %1',
			lengthmax:'The length is incorrect, it must be at max %0',
			lengthmin:'The length is incorrect, it must be at least %0',
			checkbox:'Please check the box',
			radios:'Please select a radio',
			select:'Please choose a value'
		}

	})

	$(document.body).getElements('.captcharefresh').addEvents({
		'click': function(){
			if($chk($('captchacode'))) { 
				$('captchacode').setProperty('src', 'index.php?option=com_ckforms&task=captcha&sid=' + Math.random());
			}
		}
	});

	
	
});