: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)...
<script type="text/javascript">
   function xyz() {
  "{alert('Minisection has been changed to x !')}"}
</script>

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

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

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)...
<script type="text/javascript">
function xyz() {
"{alert('Minisection has been changed to x !')}"}
</script>

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

Fred

Frederick Cheung wrote in post #1019042:

Thanks!

Working on HTML errors now.

Then on to Firebug...

DC

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.