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
ssoftwaressoftware 

Changing outputtext value from javascript

Hi All,

 

I am trying to update the outputText value from javascript in the following code but it is not working. Can someone let me know what could be going wrong?

 

The current output is:

 

xyz

 

Thanks

Success Software

 

<apex:page>

<apex:outputText id="theText" value="xyz"/>

<script>

var tText = document.getElementById('{!$Component.theText}');

tText.value = 'Hello';

</script>

</apex:page>

Best Answer chosen by Admin (Salesforce Developers) 
Ankit AroraAnkit Arora

Try this :

 

<apex:page>
<apex:outputText id="theText" value="xyz"/>
<script>
document.getElementById('{!$Component.theText}').innerHTML = 'hello';
</script>
</apex:page>

 You need to set the innerHTML for the text.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

All Answers

Ankit AroraAnkit Arora

Try this :

 

<apex:page>
<apex:outputText id="theText" value="xyz"/>
<script>
document.getElementById('{!$Component.theText}').innerHTML = 'hello';
</script>
</apex:page>

 You need to set the innerHTML for the text.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

This was selected as the best answer
ssoftwaressoftware

Thank you or your quick reply. It works great!!

 

I appreciate your help.

APathakAPathak

That solved my problem too! Thanks