You need to sign in to do that
Don't have an account?
Joe B.ax302
{!$Component} in Form does not return an Id
Hi all,
I'm not sure if this is expected functionality:
The id for the pageBlock will return; but not the one for the inputText.
Does anyone know why this is?
I would also like to include an inputText field in a repeater or pageBlockTable and have the id be dynamically created for each row. Asking too much?? :-) I know that this works visually:
Thanks in advance if anyone can help.
Code:
<apex:page > <script type="text/javascript"> window.onload = new function() { alert('{!$Component.pbHelloWorld}'); alert('{!$Component.txtFoo}'); }; </script> <apex:pageBlock id="pbHelloWorld" title="Hello, World"> </apex:pageBlock> <apex:form> <apex:inputText id="txtFoo" /> </apex:form> </apex:page>
The id for the pageBlock will return; but not the one for the inputText.
Does anyone know why this is?
I would also like to include an inputText field in a repeater or pageBlockTable and have the id be dynamically created for each row. Asking too much?? :-) I know that this works visually:
Code:
<apex:pageBlock> <apex:pageBlockTable> <apex:column> <apex:form> <apex:inputText id="row" /> </apex:form> </apex:column> </apex:pageBlockTable> </apex:pageBlock>
Thanks in advance if anyone can help.
To refer to a Visualforce component in JavaScript or another Web-enabled language you must specify a value for the id attribute for that component and then use that value with the $Component global variable in your code. Component IDs are accessed hierarchically on a page. For example, to access a data table with id="tableID" contained in a page block with id="blockID", use the following expression: $Component.blockID.tableID.
If the component you want to access is a direct descendant or a sibling of the $Component variable in the DOM hierarchy, you do not need to specify an ID for outer-level components. The system dynamically assigns IDs to the outer components and automatically determines the hierarchy for you.
For example, suppose you want to access a data table component that is contained in an <apex:pageBlock> tag. You only need to specify the ID for the <apex:dataTable> tag. This way, if the page hierarchy is ever changed (for example, if an <apex:detail> tag is wrapped around the table), you do not have to change your code.
basically you use $component from inside your visualforce tree, not in javascript
like this
Works like a charm:
if you look at the source, gives you these ids (assume I have two contacts on that account, so it prints out two rows)
A word of advice though on that code. In general it is a bad idea to have a form within an iterating component. It's probably best for you to move the form outside of the pageBlock, otherwise you are generating a form for every row.
Message Edited by jwetzler on 05-30-2008 09:48 AM
And I wrote this visual force code... the idea is to multiple the value in the input box by 100