I am having a difficult time trying to get an input text value from an element that is inside a template.
I notice when inspecting the page that between the tags of define and the form the page is adding a new span.
When the below form is outside the define section the javascript works fine and the inspect element looks like:
j_id0:theForm:billingCity
However, when i save it inside the define section a new element is added and the element looks like
j_id0:j_id2:theForm:billingCity
The VF page:
<apex:page standardController="XXXX" extensions="YYY" showHeader="false" sidebar="false">
<title>VF Title</title>
<apex:composition template="PortalSiteTemplate">
<apex:define name="body">
<apex:form id="theForm">
<fieldset>
<legend>
Account Details
</legend>
<div class="form-group">
<apex:inputText value="{!billingCity}" styleClass="form-control" html-placeholder="City" id="billingCity" />
</div>
</fieldset>
</apex:form>
</apex:define>
</apex:composition>
<script type="text/javascript">
function verAcc(){
var city;
city = document.getElementById("{!$Component.theForm.billingCity}").value;
alert(city);
}
</script>
</apex:page>
document.getElementById("{!$Component.FirstElement.SecondElement.theForm.billingCity}")