# javascript...

**URL:** <https://discuss.rubyonrails.org/t/javascript/31705>\
**Category:** rubyonrails-talk\
**Created:** [July 11, 2008, 8:45am UTC](https://discuss.rubyonrails.org/t/javascript/31705 "2008-07-11T08:45:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [July 11, 2008, 8:45am UTC](https://discuss.rubyonrails.org/t/javascript/31705/1 "2008-07-11T08:45:22Z")

</div>

i've written script function ganesh.js inside "public/javascripts/" path..

ganesh.js..

function gan() { alert('hai'); } ive called that function in show.rhtml file like

\<%= image\_tag('e.image', {:id =\> e.id, :onload =\> gan()}) %\>

i cant able to call that function ...is there any other way to enable javascript function in ruby rails..pls help..

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [July 11, 2008, 9:02am UTC](https://discuss.rubyonrails.org/t/javascript/31705/2 "2008-07-11T09:02:06Z")

</div>

if i wrote script inside rhtml its working ....

\<%=link\_to\_function("add","gan()")%\> \<script type="text/javascript"\> function gan() { &nbsp;&nbsp;alert('hai'); } \</script\>

how to enable javascript function from public/javascripts folder...

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [July 11, 2008, 9:03am UTC](https://discuss.rubyonrails.org/t/javascript/31705/3 "2008-07-11T09:03:22Z")

</div>

> i've written script function ganesh.js inside "public/javascripts/" path..
> 
> ganesh.js..
> 
> function gan() { alert('hai'); } ive called that function in show.rhtml file like
> 
> \<%= image\_tag('e.image', {:id =\> e.id, :onload =\> gan()}) %\>

that would need to be

> \<%= image\_tag('e.image', {:id =\> e.id, :onload =\> "gan()"}) %\>

You would need to include the relevant javacript file using  
javascript\_include\_tag

Fred

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [July 11, 2008, 11:51am UTC](https://discuss.rubyonrails.org/t/javascript/31705/4 "2008-07-11T11:51:10Z")

</div>

It may be one of the following two reasons for getting the problem.

&nbsp;&nbsp;1. You have not included the relevant javascript in the rhtml file. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The following statement should be there in the rhtml file. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= javascript\_include\_tag 'ganesh.js' %\>

&nbsp;&nbsp;2. You have not called the javascript method inside quotes. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Try with, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= image\_tag('e.image', {:id =\> e.id, :onload =\> "gan();"}) %\>

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [July 14, 2008, 3:39am UTC](https://discuss.rubyonrails.org/t/javascript/31705/5 "2008-07-14T03:39:36Z")

</div>

THANK U VERY MUCH Karthi .....IT WORKS FINE...
