+ Start a Discussion
.Net Api.Net Api 

How to find <apex:inputText id="Ans1" value="{!Answer1}" /> apex:inputtext id in javascript

I am writing this code

var answer=document.getElementById("{!$Component.Ans1}");




but it returns the null value.


Can u please help me in this issue.










there are two ways to do this. The easy one is to change the code to


var answer = document.getElementById("Ans1");


But if you want to use the object name you need to specifiy the complete "path" to the input. It might be something like:


var answer = document.getElementById("{!$Component.theForm.theBlock.theSection.theSectionID.ChangeRequest}");


You need to give the forms and all other ensted element an Id so you can build this path. 


I'm not sure I did explain this very well, but I hope it makes sense!





Sridhar BonagiriSridhar Bonagiri



document.getElementById("componentid"); will be best way to retrive the value in apex:inputtext