Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this HTML - its a button placed at the end of a search box:

<input type="image" name="submit" id="searchSubmit" src="images/searchGif.gif" border="0" />

How do I attach a Controller action to it and what is the VF equivalent of this html?

share|improve this question
up vote 6 down vote accepted

So if you want to work with a "plain" HTML (for example to reduce the page view state size) you can use JavaScript Remoting controls or just attach an action function to your button:

<input type="button" name="submit" id="searchSubmit" onclick="doSomething();"/>

<apex:actionFunction name="doSomething" action="{!myApexMethod}" reRender="somePanel"/>
share|improve this answer
Thanks, I followed your example and it worked. Now I need to get the text from the other input field of type text to my search method on the controller. What is the right way to do it? – Dedo Dec 14 '12 at 18:38

Use an apex:commandButton with the image attribute set to the URL of the image that you want to display.

    <apex:page controller = "CustomControllerClass" >
        <apex:commandButton action="{!search}" image="images/searchGif.gif" id="theButton"/>

You may have to specify the full url to the image, depending on where you're holding the image.

You will then need to create a controller class (or extension, as the case may be), which your page is associated with and declare an action method (return type PageReference), which can then be bound to this button

public class CustomControllerClass{

public PageReference search(){
//execute logic here
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.