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

Auto submit FormAction after Listbox field selection

Go to End

5 Posts   5069 Views


Community Member, 56 Posts

22 November 2009 at 6:10am


I'm trying to obtain such behavior for my Page_Controller form:

	function changeLanguageForm()
		$arrOptions = array();
		$arrCommonLocales = i18n::get_common_languages(true);
		foreach( Translatable::get_allowed_locales() as $value )
			$langName = i18n::get_lang_from_locale($value);
			$arrOptions[$value] = $arrCommonLocales[$langName];
		$action = new FormAction('submitLanguageChange', '', null, null);
		$fields = new FieldSet(
			new ListboxField('langs', "", $arrOptions, Translatable::get_current_locale())
		$validator = new RequiredFields('langs');
		return new Form($this, 'changeLanguageForm', $fields, $action, $validator);

For pure html+js this pretty simple

<select name='myfield' onchange='this.form.submit()'>
<option .... >

I have no idea how to do that in ss way...


Community Member, 283 Posts

26 November 2009 at 6:32am

The "SS way" is to always use the Form Actions to submit a form. That said there is not straightforward way to change this.

However I would just toss out a little jQuery script on your form page to bind to the onchange event for that item.


Community Member, 56 Posts

26 November 2009 at 9:08pm

How to do that? I suppose I have to hide submit button and fire it from js, any examples?


Community Member, 56 Posts

7 December 2009 at 11:06pm

OK I did it by jQuery:

// Standard jQuery header
;(function($) {
$(document).ready(function() {
	$("#Form_changeLanguageForm").find(":submit").css({display: "none"});// nie pokazuj szukania
	$("#Form_changeLanguageForm select").change(function(){
// Standard jQuery footer

And in Page_Controller init() method:


Works fine but in firebug console I have frustrating error:

jQuery is not defined

How to eliminate last error?


Community Member, 37 Posts

8 January 2016 at 3:15pm

If anyone has this error "jQuery is not defined" then check the order of the included javascript files. If jQuery isn't included before other required js files then you will have problems