on

In my header I have a drop-down to change the language, inside a form I would like to submit the form without any submit button, just upon selection changing

this his the generated code from my haml code

<form onchange="this.form.submit();" method="post" action="/ switch_language?locale=fr"> <select name="language" id="language_"><option value="en">Anglais</

<option selected="selected" value="fr">Français</option> <option value="de">Allemand</option></select> </form>

but I get a JS error

this.form is undefined

what did I missed ...

thanks for your help

this his the generated code from my haml code

Anglais</

Français Allemand

but I get a JS error

this.form is undefined

what did I missed …

The onchange event is on the tag, so “this” is a form and doesn’t have a “.form” method. Try doing:

<form onchange="this.submit();"...

P.S. It does feel icky having onchange=“” in your markup, but let’s worry about going to Unobtrusive Javascript later…

Cheers,

Andy

Actually, a form element doesn't have an "onchange" event handler -- you want to put that on the select, referring to the parent form...

Good catch Hassan

Thanks Hassan

I modified my code ( onchange is now on the select ) but it seems not to be working ... I don't have a submit submit button ... should I add a submit button w display:none ?

Ok it runs ... I did a mistake copying the :html => { :onchange ... into the select I had to write only :onchange... into the select good

Thanks a lot

have a nice we

Are you using Firefox with Firebug? If not, you should be, because it's very good at reporting errors. :slight_smile:

What does your generated form html look like now?