:onchange in rails 3

Hi,

Anybody know why :onchange works here…
<%= select_tag “Minisections”,
options_from_collection_for_select(@minisections, :id, :title, :selected
=> @minisection.id), {:onChange => “{alert(‘Minisection has been changed
to x !’)}”} %>

but NOT here (to call a function)…

<%= select_tag “Minisections”,
options_from_collection_for_select(@minisections, :id, :title, :selected
=> @minisection.id),
{:onChange => “xyz()”} %>

The function is at the top of the .html.erb page. I have used a similar
format with :onclick and it works fine.

Thanks,

DC

On Aug 29, 2011, at 8:27 AM, Dave C. wrote:

but NOT here (to call a function)…

The function is at the top of the .html.erb page. I have used a
similar
format with :onclick and it works fine.

Visit your rendered page in a browser, view source, and copy all. Then
go to http://validator.w3.org and use the Direct Input tab and paste.
Validate your page. If it passes there, then enable Firebug in your
copy of Firefox, open up the console section, and visit your page. You
either have an HTML/DOM error or a JavaScript error. Once you figure
out which one you’re dealing with in this case, you can proceed to a
fix.

Walter

On Aug 29, 1:27pm, Dave C. [email protected] wrote:

function xyz() {
“{alert(‘Minisection has been changed to x !’)}”}

Because all that function does is create a string literal - it’s not
actually calling alert because all that is enclosed in “”.

Fred

Frederick C. wrote in post #1019042:

On Aug 29, 1:27pm, Dave C. [email protected] wrote:

function xyz() {
“{alert(‘Minisection has been changed to x !’)}”}

Because all that function does is create a string literal - it’s not
actually calling alert because all that is enclosed in “”.

Fred

Conversely, copying and pasting something found in a rails
bastardization of an html element and treating it as javascript code
won’t work.

The most basic javascript function is alert(). You can find 45,000 hits
on goolge with examples of alert(). I suggest you read at least one of
them.

Thanks 7stud,

I am trying to learn Rails, HTML, Javascript, and Ajax but am learning
on my own. No programming background. I spent a couple of days trying
to figure this out before asking the question, and did Google it . Been
working on this project for over a year (maybe longer) and have only
asked for help a few times. Up till your reply, everyone has been very
helpful.

DC

Thanks Fred,

Can’t believe I made that stupid a mistake!

DC

Heya Dave - do not let the trolls scare you - we are all beginners at
some
point - asking queations will help you learn and progress. web apps are
a
complex beast

Glad to have you in the community.
On Aug 30, 2011 12:44 PM, “Dave C.” [email protected]
wrote:


Posted via http://www.ruby-forum.com/.


You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
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.

Thanks!

Working on HTML errors now.

Then on to Firebug…

DC