You need to sign in to do that
Don't have an account?
javascript in apex
<apex:page id="ats" controller="opportunityController" tabStyle="Opportunity">
<!-- 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>
in this code java script is not working i m a trainee on this plz help me
Can you post your code using the Insert code button on the editor - (clipboard with a c inside it)?
Otherwise we can't see exactly what's going on with brackets and colons etc - they turn into smileys.
simply call the javascript function on button click,
<!-- 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 value="save" onclick="validateresedency();" />
</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>
<script type="text/javascript">
function validateresedency()
{
var av=document.getElementById("{!$Component.ats.firstpage.Residency}"}.value);
if(av=="")
{
alert('Plz Enter a valid resedency');
}
}
</script>
</apex:form>
This is your new Page
</apex:page>
<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 value="ChkValidate" onclick="validateresedency();" />
</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>
<script>
function validateresedency()
{
var av=document.getElementById("{!$Component.ats.firstpage.Residency}").value;
if(av=="")
{
alert('Plz Enter a valid Number');
}
}
</script>
</apex:form>
</apex:page>
Hey
The reason is that there are some weird rules around $Component and as a result {!$Component.ats.firstpage.Residency} is not going to return the value you expect. There's an article that details the solution here.
Cheers,
Wes
Dear Sir
i m starter with the salesforce.
your above solution is not working.
what i want to do is that there is a inputtext field,
i want to apply the the required field validation
on that . plz help i have given u the code
Thanks
Try this,
<apexage id="ats" controller="opportunityController" tabStyle="Opportunity">
<apex:sectionHeader title="new Customer Opportunity" subtitle="Step 1 to 3"/>
<h1>Congratulations</h1>
<apex:form id="firstpage">
<apexageBlock title="Customers Information">
<apex:facet name="footer">
<apexutputPanel >
<apex:commandButton action="{!Step2}" value="next" styleClass="btn" />
<apex:commandButton value="ChkValidate" oncomplete="validateresedency();" />
</apexutputPanel>
</apex:facet>
<apexageblockSection title="Account Information">
<apexanelGrid columns="2">
<apexutputLabel value="Account Name" for="accountName"></apexutputLabel>
<apex:inputField id="accountName" value="{!account.name}"/>
<apexutputLabel value="site" for="accountSite"></apexutputLabel>
<apex:inputField id="accountSite" value="{!account.site}"/>
</apexanelGrid>
</apexageblockSection>
<apexageblockSection title="Contact Information">
<apexanelGrid columns="2">
<apexutputLabel value="First Name" for="contactFirstName"></apexutputLabel>
<apex:inputField id="contactFirstName" required="true" value="{!contact.firstName}"/>
<apexutputLabel value="Last Name" for="contactLastName"></apexutputLabel>
<apex:inputField id="contactLastName" value="{!contact.lastName}"/>
<apexutputLabel value="Phone" for="contactPhone" ></apexutputLabel>
<apex:inputField id="contactPhone" required="true" value="{!contact.Phone}"/>
<apexutputLabel value="Residence"></apexutputLabel>
<apex:inputText id="Residency" />
<script>
var av=document.getElementById("{!$Component.Residency}").value;
</script>
</apexanelGrid>
</apexageblockSection>
</apexageBlock>
<script>
function validateresedency()
{
if(av==""
{
alert('Plz Enter a valid Number');
}
}
</script>
</apex:form>
function validateresedency()
{
var av=document.getElementById('{!$Component.ats.firstpage.Residency}').value;
if(av==""
{
alert('Plz Enter a valid Number');
}
}
Use the above code to get value page id must also be mentioned.