You need to sign in to do that
Don't have an account?

Fetching a value of Visualforce page to Javascript
I would like to fetch the value of count which is written below in a visualforce page into javascript and modify it. Thereafter I would like to rerender it into another field.
<apex:outputtext id= "count" value ="{!50}" />
Javascript:
a = document.getElementById('{!$Component.count}').value;
alert('a is' + a);
The above statement is used to fetch the value. When I displaying through alert, it is showing as 'a is undefined'. Can anyone please help on how to fetch the correct value.
<apex:outputtext id= "count" value ="{!50}" />
Javascript:
a = document.getElementById('{!$Component.count}').value;
alert('a is' + a);
The above statement is used to fetch the value. When I displaying through alert, it is showing as 'a is undefined'. Can anyone please help on how to fetch the correct value.
Here is the code snippet that I tried to confirm the logic :
Regards,
Lakshmi.
All Answers
Check the below link.
https://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global_component.htm
You need to use .innerHTML for outputtext.
If this resolved your issue kindly mark it as the solution.
Regards,
Lakshmi.
a = document.getElementById('{!$Component.count}').innerHTML;
This is fetching the value into javascript. How can I display the modified value in javascript in another ouputtext tag in visualforce. Can you please let me know.
document.getElementById('{!$Component.<outputtextfieldID>}').innerHTML = a;
Regards,
Lakshmi.
Thanks for you reply again. I have tried this thing before also. Setting a value in a visual force element through javascript does not work in this way.
<apex:page >
<script>
function check()
{
a = document.getElementById('{!$Component.count}').innerHTML;
document.getElementById('{!$Component.count2}').innerHTML = b;
</script>
output1: <apex:outputtext id="count" value="{!50}" />
output2: <apex:outputtext id="count2" value="" />
</apex:page>
When I ran above code, the output is
output1:50 output2:
Output2 is turning out to. be null.
Note: I do not want to involve Controller class here. My requirement is to execute this kind of logic at page level. Please share your inputs if any.
Best Regards,
Abilash
What is the value in 'b' here. That is what will be set.
If you want to set the value in a, you will have to do
document.getElementById('{!$Component.count2}').innerHTML = a;
Regards,
Lakshmi.
Here is the code snippet that I tried to confirm the logic :
Regards,
Lakshmi.
Glad that it worked. :-)