You need to sign in to do that
Don't have an account?
Aditya Rayavarapu 5
Javascript in VF
Hello,
I have an output field in a VF page. When the page is loaded, if the output field is empty, then javascript must output a text value of "Anonymous". I can get the output to generate when the page is loaded, but it is not considering whether the output field is null or not. I tried using ".value" at the end of var x, but it doesn't work. Any help? Thanks
<apex:outputfield id="first" value="{!c.FirstName__c}"/>
<output id="firstname"></output>
<script>
var x = document.getElementById('{!$Component.first}');
window.onload = function(){
if ( x !== undefined ) {
document.getElementById('firstname').value="Anonymous";
}
}
</script>
I have an output field in a VF page. When the page is loaded, if the output field is empty, then javascript must output a text value of "Anonymous". I can get the output to generate when the page is loaded, but it is not considering whether the output field is null or not. I tried using ".value" at the end of var x, but it doesn't work. Any help? Thanks
<apex:outputfield id="first" value="{!c.FirstName__c}"/>
<output id="firstname"></output>
<script>
var x = document.getElementById('{!$Component.first}');
window.onload = function(){
if ( x !== undefined ) {
document.getElementById('firstname').value="Anonymous";
}
}
</script>
do a check after the var x= document.getElementById('{!$Component.first}');
write an alert statement after the above line of code alert(x).
And also go through this link
https://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global_component.htm