</apex:pageBlock> </apex:form> <script> function validatephone() { var av=document.getElementById("{!$Component.firstpage.Residency}"}); if(av=="") { alert("Plz Enter a valid Number") } } </script> This is your new Page
<script> function validatephone() { var av=document.getElementById("{!$Component.ats.firstpage.Residency}").value; if(av=="") { alert("Plz Enter a valid Number"); } } </script>
<script> function validateresedency() { var av=document.getElementById("{!$Component.ats.firstpage.pageBlock1.pageblockSection2.Residency}").value; alert(av); if(av=="") { alert('Plz Enter a valid Number'); } } </script>
What sort of validation are you looking forward??
I mean if you want to apply validation on a textbox then
<apex:page id='pg1'>
<apex:form id='frm1'>
<apex:inputtext id="idInputTxt" value="{!usrName}"/>
<apex:commandButton value="Save" onClick="funcRedirect();"/>
<script>
function funcRedirect()
{
if(document.getElementById("{!$Component.pg1.frm1.idInputTxt}").value == 'Gomsuey')
{
alert('USERNAME CORRECT');
}
else
{
alert('USERNAME INCORRECT');
}
}
</script>
</apex:form>
</apex:page>
Hope its helpful !!!
<!-- Begin Default Content REMOVE THIS -->
<apex:sectionHeader title="new Customer Opportunity" subtitle="Step 1 to 3"/>
<h1>Congratulations</h1>
<apex:form id="firstpage">
<apex:pageBlock title="Customers Information">
<apex:facet name="footer">
<apex:outputPanel >
<apex:commandButton action="{!Step2}" value="next" styleClass="btn" />
<apex:commandButton action="{!save}" value="save" onclick="validatephone();" styleClass="btn" />
</apex:outputPanel>
</apex:facet>
<apex:pageblockSection title="Account Information">
<apex:panelGrid columns="2">
<apex:outputLabel value="Account Name" for="accountName"></apex:outputLabel>
<apex:inputField id="accountName" value="{!account.name}"/>
<apex:outputLabel value="site" for="accountSite"></apex:outputLabel>
<apex:inputField id="accountSite" value="{!account.site}"/>
</apex:panelGrid>
</apex:pageblockSection>
<apex:pageblockSection title="Contact Information">
<apex:panelGrid columns="2">
<apex:outputLabel value="First Name" for="contactFirstName"></apex:outputLabel>
<apex:inputField id="contactFirstName" required="true" value="{!contact.firstName}"/>
<apex:outputLabel value="Last Name" for="contactLastName"></apex:outputLabel>
<apex:inputField id="contactLastName" value="{!contact.lastName}"/>
<apex:outputLabel value="Phone" for="contactPhone" ></apex:outputLabel>
<apex:inputField id="contactPhone" required="true" value="{!contact.Phone}"/>
<apex:outputLabel value="Residence"></apex:outputLabel>
<apex:inputText id="Residency" />
</apex:panelGrid>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
<script>
function validatephone()
{
var av=document.getElementById("{!$Component.firstpage.Residency}"});
if(av=="")
{
alert("Plz Enter a valid Number")
}
}
</script>
This is your new Page
</apex:page>
Hey Check this out :
<apex:page id="ats" tabStyle="Opportunity">
<apex:form id="firstpage">
<apex:outputLabel value="Residence"></apex:outputLabel >
<apex:inputText id="Residency"/>
<apex:commandButton value="Validate" onclick="validatephone();" />
<script>
function validatephone()
{
var av=document.getElementById("{!$Component.ats.firstpage.Residency}").value;
if(av=="")
{
alert("Plz Enter a valid Number");
}
}
</script>
</apex:form>
</apex:page>
Hey
You have two options that are quite elegant,
I'd recommend the second option, it's neat and easy to implement.
Cheers,
Wes
<apex:page>
<apex:form>
<apex:inputText id="totArea" value="{!objSubFacility.subfacility.TotalArea__c}" onchange="funcRedirect(this);" /><script>
function funcRedirect(id1){
var nameRegxp1 = /^([0-9_.]+)$/;
var val=document.getElementById(id1.id).value;
if (nameRegxp1.test(val) != true){
alert("Enter valid number");
document.getElementById(id1.id).value='';
document.getElementById(id1.id).focus();
return false;
}
return true; }
</script>
</apex:form>
</apex:page>
try this
<apex:inputText id="totArea" value="hello" onchange="funcRedirect(this);" />
small correction