function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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}");

alert(answer);

 

 

but it returns the null value.

 

Can u please help me in this issue.

 

 

 

 

 

 

HaagenHaagen

Hi,

 

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!

 

Cheers!

 

Martin

Sridhar BonagiriSridhar Bonagiri

Hi,

 

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