I am trying to get the value of a text field in a VF page in Java Script. Below is my VF page.
<apex:page id="thepage" standardController="Opportunity" extensions="OpportunityExt">
<apex:form id="theform">
<script type="text/javascript">
function initialize(){
alert('called' + document.getElementById("thePage:theform:atextId").value);
}
</script>
<apex:outputPanel id="inputId">
<apex:commandLink id="saveBtn" onclick="initialize();" value="Search"/>
</apex:outputPanel>
<apex:outputPanel id="outputId">
<apex:outputLabel value="{!$objecttype.Opportunity.fields.IsClosed__c.label}"/>
<apex:actionRegion >
<apex:inputField value="{!Opportunity.IsClosed__c}" id="closedcheckboxId"/>
</apex:actionRegion>
<apex:outputLabel value="{!$objecttype.Opportunity.fields.OrderNumber__c.label}"/>
<apex:actionRegion >
<apex:inputField value="{!Opportunity.OrderNumber__c}" id="atextId"/>
</apex:actionRegion>
</apex:outputPanel>
</apex:form>
</apex:page>
When I click the link I get this error in the inspect window.
Cannot read property 'value' of null
I might be missing something here. I checked the path of the text field using inspect window and I saw:
<input id="thepage:theform:atextId" maxlength="8" name="thepage:theform:atextId" size="20" type="text" value="731645">
What am I missing here. Why do I get a null?