You need to sign in to do that
Don't have an account?

how to write script validaions in visualforce page
hi, how to write script validations for Firstname, email,phone,.............
please help me
<apex:page controller="leadcontroller">
<script>
</script>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel value="First Name" for="fname"/>
<apex:inputtext value="{!FirstName}" id="fname"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Last Name" for="lname"/>
<apex:inputtext value="{!LastName}" id="lname"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Phone" for="phone"/>
<apex:inputtext value="{!phone}" id="phone"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Email" for="email"/>
<apex:inputtext value="{!Email}" id="email"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="save"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
I assume you want to do a "Client-side" validation - validate a page before it is posted to the server. This requires javascript to be added to the page. Here's a sample code I wrote to make sure the the "First Name" field has a value in it.
Of special note is the way Salesforce changes the IDs of objects - you cannot refer to an element by just its ID defined in your visualforce page. Salesforce changes the object's ID to something like [Form Id]:[page Block Id]:[page block section id]:[object id].
You can run this in a standalone fashion, and tweak the code if you wish to try out different things :-
Here's the visualforce page :-
And here's the Apex class :-