+ Start a Discussion
SandrineSandrine 

command button to clear the input text values

Hello,

I have a button like below,
<apex:inputText value="{!search}" id="search" />
controller{

public String search{get;set;}

funtion(){

}
}
I want to have a another button , which will clear the input text on front end and also in the back end

thank you for suggestions !!



 
Best Answer chosen by Sandrine
James LoghryJames Loghry
If you're familiar with jquery, you could get by with something similar to the following:
 
<script>
$j = jQuery.noConflict();

$j(document).ready(function() {
    $j("[id$=cancel]").change(function(){
        $j("[id$=search]").val("");
    }
}
</script>

Otherise, you could write another Apex method called clear that sets your search member variable to an empty string, and then call that via an action function.

All Answers

James LoghryJames Loghry
If you're familiar with jquery, you could get by with something similar to the following:
 
<script>
$j = jQuery.noConflict();

$j(document).ready(function() {
    $j("[id$=cancel]").change(function(){
        $j("[id$=search]").val("");
    }
}
</script>

Otherise, you could write another Apex method called clear that sets your search member variable to an empty string, and then call that via an action function.
This was selected as the best answer
Dushyant SonwarDushyant Sonwar

Hi Sandrine,

Are you saying you want to clear all the textboxes values in your form?
If yes, then you can use javascript form.reset() method
The reset() method resets the values of all elements in a form

<script>
function cleartext(){
    document.getElementsByClassName('abc')[0].reset();
}
</script>
  <apex:form id="frm" html-class="abc">
      <apex:inputtext />
      <apex:inputtext/>
      <apex:commandbutton value="clear values" onclick="cleartext();return false;"/>
  </apex:form>
 

SijuSiju
Simply we can do it like this.

<apex:form >
<apex:inputtext value="{!InputValueVariable}"/>
<apex:commandButton value="ClearButton" onclick="this.form.reset();return false;" />
</apex:form>