function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rahul BorgaonkarRahul Borgaonkar 

Clear inputtextarea value onclick event

Hi,

I have apex:inputtextarea field which has default inital value. Onclick event on this field it should get empty (blank). How could I acheive this?
<apex:inputTextarea rows="1" id="inputpa" value="{!ebrecs.Attendance_Notes__c}"/>
Thanks,

Rahul
Best Answer chosen by Rahul Borgaonkar
badibadi
 <apex:page>
 <!-- if you have jquery in static resource <apex:includescript value="{!URLFOR($Resource.jquery, 'jquery-1.10.2.min.js')}" /> -->
     <apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"/>
<script>
       var  j$= jQuery.noConflict();
       function clearMe(){
           j$("[id$=inputpa]").val('');
       }
</script>
<apex:form>
          <apex:inputTextarea rows="1" id="inputpa" value="{!ebrecs.Attendance_Notes__c}" onclick="clearMe();" />
</apex:form>
</apex:page>

All Answers

badibadi
 <apex:page>
 <!-- if you have jquery in static resource <apex:includescript value="{!URLFOR($Resource.jquery, 'jquery-1.10.2.min.js')}" /> -->
     <apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"/>
<script>
       var  j$= jQuery.noConflict();
       function clearMe(){
           j$("[id$=inputpa]").val('');
       }
</script>
<apex:form>
          <apex:inputTextarea rows="1" id="inputpa" value="{!ebrecs.Attendance_Notes__c}" onclick="clearMe();" />
</apex:form>
</apex:page>
This was selected as the best answer
JayantJayant

You may use either actionSupport or actionFunction. actionFunction example is given below.

e.g.
<script type="text/javascript">
function clearTextJS()
{
    clearTextAF();
}
</script>

<apex:page>...
<apex:actionFunction name="clearTextAF" action="{!clearText}" immediate="true"/>
<apex:inputTextarea rows="1" id="inputpa" value="{!ebrecs.Attendance_Notes__c}" onclick="clearTextJS();"/>


Define method clearText() in Controller/Extension. You may either use rerender with actionFunction or return a PageReference from the method clearText().

---------------------------------

If this resolves your issue, please mark the question as Resolved.