You need to sign in to do that
Don't have an account?
Any sample code for field validation(Vsualforce page)?
I wrote a visual force page and custom controller for simple addition and subtraction.In the page i wrote some simple java script code for field validation but it wasn't work. Any sample code for field validation(Vsualforce page)?
Thanks,
Karan
<apex:page controller="Arithmatic_opp">
<apex:form id="firstpage">
<apex:pageBlock title="Calculator">
<apex:pageBlockSection collapsible="0">
<apex:pageblocksectionitem >
<apex:outputlabel > Enter A value</apex:outputlabel>
<apex:inputText value="{!A_value}" id="a1"/>
</apex:pageblocksectionitem>
<apex:pageBlockSectionItem >
<apex:outputlabel > Enter B value</apex:outputlabel>
<apex:inputText value="{!B_value}" id="b1"/>
</apex:pageBlockSectionItem>
<apex:commandButton value="Addition" onclick="valid()"/>
<apex:outputlabel id="one"> {!operation} {!result}</apex:outputlabel>
<script>
function valid()
{
var na1=document.getElementById('{!$Component.firstpage.a1}');
var na2=document.getElementById('{!$Component.firstpage.b1}');
if(na1==" "&&na2==" ")
{
alert("Enter A and B values");
}
if(na1==" ")
{
alert("please ente A value ");
}
var na2=document.s.pass.value;
if(na2==" ")
{
alert("please ente B value");
}
}
</script>
<apex:commandButton value="Subtraction" action="{!subb}"/>
<apex:outputlabel id="Two"> {!operation1} {!result}</apex:outputlabel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class Arithmatic_opp
{
public Arithmatic_opp() {
}
private final lead l;
public Arithmatic_opp(ApexPages.StandardController stdController) {
this.l = (lead)stdController.getRecord();
}
public integer A_value{get;set;}
public integer B_value{get;set;}
public integer Result{get;set;}
public string operation{get;set;}
public string operation1{get;set;}
public pagereference subb()
{
result=A_value-B_value;
operation='Result after performing Subtraction operation';
return null;
}
public pagereference Add()
{
result=A_value+B_value;
operation1='Result after performing Addition operation';
return null;
}
}
Follow this link http://www.cloudforce4u.com/2013/07/show-error-message-in-visualforce.html its help you for some sample code for validation in vf Page.
below is sample code. Thanx
Pritam Shekhawat
I watched the blog but there he used apex custom controller for the validation.
But i need javascript code for validating the fields.