# Button\_to\_function with image?

**URL:** <https://www.ruby-forum.com/t/button-to-function-with-image/104564>\
**Category:** Rails\
**Created:** [May 19, 2007, 5:20pm UTC](https://www.ruby-forum.com/t/button-to-function-with-image/104564 "2007-05-19T17:20:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [May 19, 2007, 5:20pm UTC](https://www.ruby-forum.com/t/button-to-function-with-image/104564/1 "2007-05-19T17:20:16Z")

</div>

Hi:

does button\_to\_function allow the use of an image? I tried it in place  
of the text with “image\_tag” and it doesn’t work. Maybe some form of  
button\_to?

Any direction you can give would be great!

Mike

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [May 19, 2007, 8:13pm UTC](https://www.ruby-forum.com/t/button-to-function-with-image/104564/2 "2007-05-19T20:13:12Z")

</div>

Mike,

> does button\_to\_function allow the use of an image? I tried it in  
> place  
> of the text with “image\_tag” and it doesn’t work. Maybe some form  
> of  
> button\_to?

I couldn’t find a way to pass an image as parameter, but you can  
fabricate it yourself.

\<%= content\_tag(:button, image\_tag(“ok.png”)+“Submit”, :type =\>  
“submit”) %\>

A good candidate for a helper.

## Alain R.

[http://blog.ravet.com](http://blog.ravet.com)

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [May 20, 2007, 4:05pm UTC](https://www.ruby-forum.com/t/button-to-function-with-image/104564/3 "2007-05-20T16:05:53Z")

</div>

Alain R. wrote:

> Mike,
> 
> > does button\_to\_function allow the use of an image? I tried it in  
> > place  
> > of the text with “image\_tag” and it doesn’t work. Maybe some form  
> > of  
> > button\_to?
> 
> I couldn’t find a way to pass an image as parameter, but you can  
> fabricate it yourself.
> 
> \<%= content\_tag(:button, image\_tag(“ok.png”)+“Submit”, :type =\>  
> “submit”) %\>
> 
> A good candidate for a helper.
> 
> ## Alain R.
> 
> [http://blog.ravet.com](http://blog.ravet.com)

Hi Alain:

Thank you so much! It worked. But here’s what I did:  
\<%= content\_tag(:button, image\_tag(“btn\_send.gif”), :type =\> “submit”,  
:onclick =\> “closeiframe();”) %\>  
So when I do this, it puts a button-box around “image\_tag”. Any further  
suggestions???

Thanks again!

Mike

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [May 20, 2007, 6:47pm UTC](https://www.ruby-forum.com/t/button-to-function-with-image/104564/4 "2007-05-20T18:47:11Z")

</div>

Mike,

> But here’s what I did:  
> \<%= content\_tag(:button, image\_tag(“btn\_send.gif”), :type =\>  
> “submit”, :onclick =\> “closeiframe();”) %\>  
> So when I do this, it puts a button-box around “image\_tag”.

Yep. That’s what you’re looking for, arent’t you?  
see:  
[Particletree » Rediscovering the Button Element](http://particletree.com/features/rediscovering-the-button-element/)

Note: if you don’t need text in the button, there is :  
image\_submit\_tag  
[Peak Obsession](http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M000613)

## Alain R.

[http://blog.ravet.com](http://blog.ravet.com)

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [December 26, 2007, 3:20pm UTC](https://www.ruby-forum.com/t/button-to-function-with-image/104564/5 "2007-12-26T15:20:24Z")

</div>

Mike D. wrote:

> Hi:
> 
> does button\_to\_function allow the use of an image? I tried it in place  
> of the text with “image\_tag” and it doesn’t work. Maybe some form of  
> button\_to?
> 
> Any direction you can give would be great!
> 
> Mike

Mike, give this a go.

link\_to\_function(image\_tag(“delete”), “if (confirm(‘Really?’))  
do\_delete()”)  
Produces:  
  
  ![Delete](https://www.ruby-forum.com/images/delete.png?)

RJS template:

\<%= link\_to\_function image\_tag(‘foo.jpg’, :class =\> “foobar”) do |page|  
page.visual\_effect :blind\_up, “foo\_#{@bar.id}”  
page.show “foo\_#{@bar.id}”  
end %\>

I also recommend you visit:  
[http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#M001061](http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#M001061)

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [February 25, 2008, 8:54pm UTC](https://www.ruby-forum.com/t/button-to-function-with-image/104564/6 "2008-02-25T20:54:49Z")

</div>

Hi,

Is there a way to have both text and image in button\_to\_function?

Neha

On Dec 26 2007, 9:20 am, Fulvio Cusumano \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [February 25, 2008, 8:54pm UTC](https://www.ruby-forum.com/t/button-to-function-with-image/104564/7 "2008-02-25T20:54:51Z")

</div>

Hi,

Is there a way to have both text and image in button\_to\_function?

Neha

On May 20 2007, 9:05 am, Mike D. \<rails-mailing-l…@andreas-
