Forum: Ruby on Rails function definition inside script in remote call

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
cfingerh (Guest)
on 2007-05-24 01:37
(Received via mailing list)
I'm using remote request to update a div with a table. At the end of
the table I have some javascript where I define a function
--------------------------------------
# start table.rhtml

<table>
<tr onclick="update_values()">
etc...
</tr></table>

<script>
function update_values()
{
   do_something
}
</script>

# end table.rhtml
----------------------------

But when I try to call that function i got the error "update_values is
not defined".
I have evalscript:true
If i put for example alert('hello') after the function, i get the
alert when the script is loaded, but the function (Conclusion:  the
script is executed but the function is not defined)

I don't understand. For example, the function es executed if I change
the script to
--------
<script>
function update_values()
{
   do_something
}
update_values()
</script>

-------

But It does not work if I change it to

--------
<script>
function update_values()
{
   do_something
}
</script>
<script>
update_values()
</script>

-------

??

Thanks
This topic is locked and can not be replied to.