+ Start a Discussion
WEN JIEWEN JIE 

How to get textarea value by js on vf

Hi,

 

I have a field as a rich textarea. I use inputField display this field on my vf page. But I don't know how to get the value by js or jquery. And I foung this is an iframe generagte automatically when I check the page source.

 

Does anyone knows this?

 

Thank you!

Shiv ShankarShiv Shankar

<apex:page>

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> // invoke jQuery

<script>

      alert( $('[Id $= "Your_text_area_Id"]').val()) ; // alerting the value of text area

</script>

</apex:page>

Adam HowarthAdam Howarth

Can you post the source.

 

If you can add a style class to the field, then you can retrieve the value like this:

 

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<apex:inputText styleClass="value" value="{!yourField}" id="textField"/>
 
 <script>
      alert( $('.value').val()) ; // alerting the value of text area
 </script>

// This doesnt work
 alert( $('[Id $= "Your_text_area_Id"]').val()) ; // alerting the value of text area
// Or this
 alert( $('#Your_text_area_Id').val()) ; // alerting the value of text area

 Using Ids in jQuery doesnt really work in Salesforce as the IDs change based on the containers. so it will turn into something like j_id0:j_id2:textField

 

 

Akhilesh DahatAkhilesh Dahat
You can get the value of the textarea using $( 'textarea[id$=Your_text_area_Id]').val();