# Javascript in link\_to?

**URL:** <https://www.ruby-forum.com/t/javascript-in-link-to/53156>\
**Category:** Rails\
**Created:** [January 26, 2006, 9:29pm UTC](https://www.ruby-forum.com/t/javascript-in-link-to/53156 "2006-01-26T21:29:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_McGrath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8e8cbc/32.png) [@John\_McGrath](https://www.ruby-forum.com/u/John_McGrath)\
**Post date:** [January 26, 2006, 9:29pm UTC](https://www.ruby-forum.com/t/javascript-in-link-to/53156/1 "2006-01-26T21:29:15Z")

</div>

having trouble finding how to include a random chunk of javascript (an  
onclick event handler) in a link\_to generated link.

at first i thought i could use the html\_options field, but if i  
understand  
correctly, that only supports :confirm, :popup, and :post options.

hope i’m wrong. anyone know different?

john

---

<div class="post-metadata">

**Author:** ![John\_McGrath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8e8cbc/32.png) [@John\_McGrath](https://www.ruby-forum.com/u/John_McGrath)\
**Post date:** [January 26, 2006, 9:48pm UTC](https://www.ruby-forum.com/t/javascript-in-link-to/53156/2 "2006-01-26T21:48:46Z")

</div>

John McGrath wrote:

> having trouble finding how to include a random chunk of javascript (an  
> onclick event handler) in a link\_to generated link.
> 
> at first i thought i could use the html\_options field, but if i  
> understand  
> correctly, that only supports :confirm, :popup, and :post options.
> 
> hope i’m wrong. anyone know different?
> 
> john

pretty much anything you put in the html options will show up in the  
html, except for those few exceptions. Just put “onclick”=\>“random  
code” in and try it.

\_Kevin

---

<div class="post-metadata">

**Author:** ![John\_McGrath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8e8cbc/32.png) [@John\_McGrath](https://www.ruby-forum.com/u/John_McGrath)\
**Post date:** [January 26, 2006, 9:59pm UTC](https://www.ruby-forum.com/t/javascript-in-link-to/53156/3 "2006-01-26T21:59:27Z")

</div>

worked, thanks much.
