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.

Archive /

Our old forums are still available as a read-only archive.

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

Onchange event in CMS


Go to End


3 Posts   1761 Views

Avatar
UncleCheese

Forum Moderator, 4102 Posts

3 September 2008 at 4:13am

I'm trying to unobtrusively attach an onchange event to a select box on my CMS page. I've figured out that i can add custom script to a specific module using the augmentInit() function off the DataObjectDecorator.

What's confusing to me is that the window.onload() event seems to fire when the silverstripe logo comes up, which is before my select box is loaded into the DOM.

Anyone know how this is usually done?

Avatar
ajshort

Community Member, 244 Posts

3 September 2008 at 9:58am

Edited: 03/09/2008 9:58am

Hi UncleCheese,

something like this is normally used:

Behaviour.register({
	'select.domSelector' : {
		initialize: function () {
			// etc
		},
		onclick: function() {
			//etc
		}
	}
});

Not only will this get applied on page startup, but itll also be reapplied whenever a page is loaded using AJAX.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

4 September 2008 at 5:08am

Perfect! What a great solution. So glad I posted here. I was sure no one would have an answer!