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

Using JavaScript to Reference Components issue
Regarding Using JavaScript to Reference Components we can get id of a component in JavaScript using
{!$Component.thePanel}
Please, imagine that we have next page:
<apex:page > <apex:form id="form01"> </apex:form> <script type="text/javascript"> alert('{!$Component.form01}'); </script> </apex:page>
What do you think you will get in alert? Right! bla-bla-bla:form01 And I have it. Nice.
Next step.
Please, imagine:
<apex:page > <apex:form id="form01" > <apex:pageBlock id="pageBlock02" > </apex:pageBlock> </apex:form> <script type="text/javascript"> alert('{!$Component.pageBlock02}'); </script> </apex:page>
What do you think you will get in alert? Right! bla-bla-bla:form01:pageBlock02
If you have it - you are lucky! I don't.
Now remove form tag. - bla-bla-bla:pageBlock02
WTH? What am I doing wrong?
I want to se bla-bla-bla:form01:pageBlock02
Here you go! http://www.salesforce.com/us/developer/docs/pages/Content/pages_best_practices_accessing_id.htm
Here we have what I want. Why there it is working???
This works. WTH???
OK.
Got it.
All Answers
Hi,
Try this - alert('{!$Component.form01.pageBlock02}');
Thanks
Hi Sureka,
Sorry for wane and miserable example. In a real application it is more complicated. Like:
And it doesn't work. If I put all ids than it works. But it's not really interesting. It worked half a year ago perfectly. Why it isn't working now...
And your example works fine. But code above doesn't.
Usually only when you put all the ids, it will work.
As far as I see it, it depends on tag's level. When it is second level - it works fine. But when it is deeper than it doesn't. Like in mine last example where I have 4th level.
...
In more complex example I can see that you are right. But actually, than there are no sence in this $Component stuff...
Here you go! http://www.salesforce.com/us/developer/docs/pages/Content/pages_best_practices_accessing_id.htm
Here we have what I want. Why there it is working???
This works. WTH???
OK.
Got it.