I am having in rendering the onchange:
My syntax is:

<%= f.select  :country, {"Afghanistan" => "Afghanistan",
                "Aland Islands" => "Aland Islands",
                "Zimbabwe" => "Zimbabwe"
                }, :prompt => "Select", 
:html_options=>{:onchange=>"display();"} %>

Can you point out the mistake in this syntax??

On Tuesday, April 13, 2010 11:22:37 AM UTC-4, andyjeffries wrote:
>
> I am writing following code for showing the drop down:-
>> <%= select("test", "type", ["test1", "test2"],
>> :onchange=>"alert('Test');")%>
>>
>> My problem is I have to add onchange event and call a javascript.
>> Can anyone point me what is problem with my syntex?
>>
>
> Easy one...
>
> http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/select
>
> The first hash is Select options, the second is HTML options.  So you're 
> passing :onchange through as an option to the Rails helper, rather than 
> having it pass through to an HTML attribute.  What you want to do is this:
>
> <%= select("test", "type", ["test1", "test2"], {}
> {:onchange=>"alert('Test');"} )%>
>
> Note the empty {} after your normal parameter, that's the empty select 
> options, then your :onchange is in the HTML options hash.
>
> Cheers,
>
>
> Andy
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/KIS19m1skH8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to