how do i represent document.getElementById('page1:form2:amount') in jquery?
How can I represent
document.getElementById('page1:form2:amount')
in jQuery
I know I can use
$('#amount')
to access the id amount.
The id amount is an <apex:inputText/>
type which is how an input text is represented in the Visualforce page. To access this id I would need to use the hierarchy of page->form->id.
Thanks
Prady
Update: Code used in Visualforce page.
<apex:page controlle开发者_StackOverflow社区r="acontroller" id="page1">
<apex:form id="form2">
<apex:inputText value="{!amt}" id="amount" onchange="calenddate();"/>
</apex:form>
</apex:page>
I know it's a little bit late, but another way to do it would be with the jQuery Attribute ends with selector (http://api.jquery.com/attribute-ends-with-selector/).
You know that the id that you put in the apex code is always the last one on the generated id. So you can do jQuery('[id$="amount"]')
.
What this does is select the part of the id attribute that ends with amount (you need to be certain there are no other fields end this way).
This has worked perfect for me in the past.
what you can do is get the form instance and find all the input type text(not necessary) and get the id attribute from the instance
<form id="myform">
<input type="text" value="hello1" id="1">
<input type="text" value="hello2" id="2">
<input type="text" value="hello3" id="3">
<input type="text" value="hello4" id="4">
</form>
$('#myform > input[type="text"]').each(function(key,value){
$(value).attr('id');
})
and as of your server-side code, anyways it will be converted to standard HTML format on client side and javascript will read the final HTML tags only. so go to source and find what exactly is the replacment for and then use that tag to be searched in the jQuery function
you can pass selectors as if you would write them with CSS.
$('#page1 #form2 #amount').doSomething(...)
As selectors in jQ work from right to left it would mean: find element with id #amount which have a parent with id #form2 and make sure that they have a parent #page1 and only then do something.
more on jQ selectors @api.jquery.com
精彩评论