# Problem with onload

**URL:** <https://www.ruby-forum.com/t/problem-with-onload/177282>\
**Category:** Rails\
**Created:** [October 14, 2009, 2:05pm UTC](https://www.ruby-forum.com/t/problem-with-onload/177282 "2009-10-14T14:05:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [October 14, 2009, 2:05pm UTC](https://www.ruby-forum.com/t/problem-with-onload/177282/1 "2009-10-14T14:05:53Z")

</div>

Hi all,  
Does someone know why the following code doesnÂ´t work if it is embedded  
in a partial?in a regular .rhtml file works well.

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [October 14, 2009, 2:26pm UTC](https://www.ruby-forum.com/t/problem-with-onload/177282/2 "2009-10-14T14:26:22Z")

</div>

2009/10/14 Rafael R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi all,  
> Does someone know why the following code doesnÂ´t work if it is embedded  
> in a partial?in a regular .rhtml file works well.

Check the generated html in your browser if you have not done that  
already (View, Page source or similar). Also try pasting the entire  
html into the w3c html validator to check there are no errors.

Colin

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [October 14, 2009, 4:33pm UTC](https://www.ruby-forum.com/t/problem-with-onload/177282/3 "2009-10-14T16:33:25Z")

</div>

Rafael R. wrote:

> Hi all,  
> Does someone know why the following code doesnÂ´t work if it is embedded  
> in a partial?in a regular .rhtml file works well.

I’m not sure on a quick look. But I do notice a couple of tangential  
issues that might or might not be related:

- If you’re using Rails 2.x, the .rhtml suffix is deprecated. Use  
.html.erb .

- JavaScript really belongs in separate files, not mixed into HTML.  
This is especially helpful for code like yours that has to be available  
before the page is done loading. At the very least, try moving the

 into the element. Best, -- Marnen Laibow-Koser http://www.marnen.org removed\_email\_address@domain.invalid
