You need to sign in to do that
Don't have an account?
Pushkar
Accessing components using their Id in a visualforce page
Hi,
The component Id is not available through {!$Component.<Id>} when refered to in a script at the end of the visualforce page.
Though it is available if I add a script tag just after the element.
e.g.
<apex: Page standardController="Account">
<apex: form>
<apex: PageBlock>
<apex:inputField id="input_Id" value="{!account.Id}"/>
<script type="text/javascript">
alert("id= {!$Component.input_Id}");
</script>
</apex: PageBlock>
</apex:form>
</apex: Page>
The above one works, but the following fails
<apex: Page standardController="Account">
<apex: form>
<apex: PageBlock>
<apex:inputField id="input_Id" value="{!account.Id}"/>
</apex: PageBlock>
</apex:form>
<script type="text/javascript">
alert("id= {!$Component.input_Id}");
</script>
</apex: Page>
The component Id is not available through {!$Component.<Id>} when refered to in a script at the end of the visualforce page.
Though it is available if I add a script tag just after the element.
e.g.
<apex: Page standardController="Account">
<apex: form>
<apex: PageBlock>
<apex:inputField id="input_Id" value="{!account.Id}"/>
<script type="text/javascript">
alert("id= {!$Component.input_Id}");
</script>
</apex: PageBlock>
</apex:form>
</apex: Page>
The above one works, but the following fails
<apex: Page standardController="Account">
<apex: form>
<apex: PageBlock>
<apex:inputField id="input_Id" value="{!account.Id}"/>
</apex: PageBlock>
</apex:form>
<script type="text/javascript">
alert("id= {!$Component.input_Id}");
</script>
</apex: Page>
In order to acees the input value.
You have to give id for form also then it will work.
<apex: Page standardController="Account">
<apex: form id="abc">
<apex: PageBlock id="def">
<apex:inputField id="input_Id" value="{!account.Id}"/>
</apex: PageBlock>
</apex:form>
<script type="text/javascript">
alert("id= {!$Component.abc.def.input_Id}");
</script>
</apex: Page>
Reason for working in the first one is
You placed the script inside the javascript that's why it is executing fine.