You need to sign in to do that
Don't have an account?
Changing value of apex:outputText from javascript
Hi,
Why document.getElementById('{!$Component.ZoomName}') is always returning null?
We have an apex page where an outputText (id="ZoomName") is defined. In javascript we want to change the value of ZoomName, but {!$Component.ZoomName} is always returning null.
<apex:outputText value="30 dias" id="ZoomName" styleClass="chronoline-zoom-text"/ >
....
<script type="application/javascript">
.....
function loadZooms(){
var zoomRecord = new Object();
var zoomArray = new Array();
zoomRecord.Id = 0;
zoomRecord.Name= "60 dias";
zoomRecord.visibleSpan= 5184000000;
zoomArray[zoomRecord.Id] = zoomRecord;
zoomRecord = new Object();
zoomRecord.Id = 1;
zoomRecord.Name= "30 dias";
zoomRecord.visibleSpan= 2592000000;
zoomArray[zoomRecord.Id] = zoomRecord;
zoomRecord = new Object();
zoomRecord.Id = 2;
zoomRecord.Name= "15 dias";
zoomRecord.visibleSpan= 1296000000;
zoomArray[zoomRecord.Id] = zoomRecord;
zoomRecord = new Object();
zoomRecord.Id = 3;
zoomRecord.Name= "7 dias";
zoomRecord.visibleSpan= 604800000;
zoomArray[zoomRecord.Id] = zoomRecord;
zoomRecord = new Object();
zoomRecord.Id = 4;
zoomRecord.Name= "1 dia";
zoomRecord.visibleSpan= 86400000;
zoomArray[zoomRecord.Id] = zoomRecord;
if (document.getElementById('{!$Component.ZoomName}') != null) {
document.getElementById('{!$Component.ZoomName}').value = zoomArray[defaultZoom].Name;
}
return zoomArray;
}
..........
zooms = loadZooms();
buildChronoline();
</script>
Many Thanks,
Altran
Hi Altran,
Try this,
if (document.getElementById('{!$Component.ZoomName}').value != null)
{
document.getElementById('{!$Component.ZoomName}').value = zoomArray[defaultZoom].Name;
}
Let me know if it works for you!!!
Regards,
Bharathi
Salesforce For All
Mark this post as solved, if it helps you
All Answers
Hi Altran,
Try this,
if (document.getElementById('{!$Component.ZoomName}').value != null)
{
document.getElementById('{!$Component.ZoomName}').value = zoomArray[defaultZoom].Name;
}
Let me know if it works for you!!!
Regards,
Bharathi
Salesforce For All
Mark this post as solved, if it helps you
Hi,
I have already tried that. The problem is document.getElementById('{!$Component.ZoomName}' is always null, but the element is defined at the top of the page.
Thanks,
Altran