# Button\_to\_function with text and image

**URL:** <https://www.ruby-forum.com/t/button-to-function-with-text-and-image/130274>\
**Category:** Rails\
**Created:** [February 26, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/button-to-function-with-text-and-image/130274 "2008-02-26T23:17:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![neha-rohan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@neha-rohan](https://www.ruby-forum.com/u/neha-rohan)\
**Post date:** [February 26, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/button-to-function-with-text-and-image/130274/1 "2008-02-26T23:17:27Z")

</div>

Hi,

Is there a way to have text as well as image u the button\_to\_function.  
\<%= button\_to\_function “Cancel” , “#{remote\_function()}”%\>

I have something like this and now i want the cancel should also have  
some text with it.

Neha

---

<div class="post-metadata">

**Author:** ![neha-rohan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@neha-rohan](https://www.ruby-forum.com/u/neha-rohan)\
**Post date:** [February 29, 2008, 3:34am UTC](https://www.ruby-forum.com/t/button-to-function-with-text-and-image/130274/2 "2008-02-29T03:34:21Z")

</div>

[http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#M001062](http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#M001062)  
113: def button\_to\_function(name, \*args, &block)  
114: html\_options = args.extract\_options!  
115: function = args[0] || ‘’  
116:  
117: html\_options.symbolize\_keys!  
118: function = update\_page(&block) if block\_given?  
119: tag(:input, html\_options.merge({  
120: :type =\> “button”, :value =\> name,  
121: :onclick =\> (html\_options[:onclick] ?  
"#{html\_options[:onclick]}; " : “”) + “#{function};”  
122: }))  
123: end  
See the source.  
Although I am not quite understand it, I am sure that the only way  
with which you can do this is using javascript in ‘onclick’ event, if  
there does exist a way.  
But if you want text and image before click, I think you’d better  
write html on your own.

On Feb 27, 6:17 am, “removed\_email\_address@domain.invalid”

---

<div class="post-metadata">

**Author:** ![neha-rohan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@neha-rohan](https://www.ruby-forum.com/u/neha-rohan)\
**Post date:** [February 29, 2008, 7:14pm UTC](https://www.ruby-forum.com/t/button-to-function-with-text-and-image/130274/3 "2008-02-29T19:14:45Z")

</div>

yeah thats the approach i had to follow  
🙂
