Forum: Ruby on Rails JS functions from partial not available ?

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.
Johannes (Guest)
on 2007-05-10 01:45
hey!

clicking "login" opens (ajax) a login form (partial) on my site.

this partial includes the form and javascript block.
looks like this:

<script ... >
    function validate() {
       // check form fields
    }
</script>
<form ...>

</form>

the problem is: if i try to call the validate-function from inside the
form (<input onkeyup="validate()"...) i'm getting a js error:

validate() is not defined

Why isn't that function available on my site after the partial is loaded
?

thx alot
Eric A. (Guest)
on 2007-05-10 01:56
Johannes wrote:
> hey!
>
> clicking "login" opens (ajax) a login form (partial) on my site.
>
> this partial includes the form and javascript block.
> looks like this:
>
> <script ... >
>     function validate() {
>        // check form fields
>     }
> </script>
> <form ...>
>
> </form>
>
> the problem is: if i try to call the validate-function from inside the
> form (<input onkeyup="validate()"...) i'm getting a js error:
>
> validate() is not defined
>
> Why isn't that function available on my site after the partial is loaded
> ?
>
> thx alot

Rendering a partial with Ajax usually requires the evalScripts parameter
(http://prototypejs.org/api/string/evalScripts).

I'd give that a try, otherwise just include that javascript method in
the initial page where you render the login form, that way the
javascript will surely be evaluated.

Hope that helps,
- Eric
This topic is locked and can not be replied to.