You need to sign in to do that
Don't have an account?
validation on vf page using java script
hi,
this is kiran i am developing vf page i have two fields like firstname and last name,
my condition is first name and last name are not same , if both fields are same display the error message.
i tried following code but it doesn't work
<apex:page>
<apex:form >
<apex:pageblock >
<apex:pageBlockSection >
First name:
<apex:inputtext value="{!name}" id="name2"/><br/>
Last Name:
<apex:inputText value="{!name1}" id="name3"/><br/>
<apex:commandButton onclick=" return validate" value="submit"/>
<script language="javascript">
function validate()
{
try
{
var fNameObj = document.getElementById("{!$Component.fName}");
var gNameObj = document.getElementById("{!$Component.gName}");
if(trim(fNameObj.value) == "" && trim(gNameObj.value) == "")
{
alert("Father/Guardian is mandatory!");
return false;
}
return true;
}
catch(e)
{
alert(e);
return false;
}
}
</script>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
<apex:form >
<apex:pageblock >
<apex:pageBlockSection >
First name:
<apex:inputtext value="{!name}" id="name2"/><br/>
Last Name:
<apex:inputText value="{!name1}" id="name3"/><br/>
<apex:commandButton onclick=" return validate();" value="submit"/>
<script language="javascript">
function validate()
{
try
{
var fNameObj = document.getElementById("{!$Component.name2}");
var gNameObj = document.getElementById("{!$Component.name3}");
if(trim(fNameObj.value) == "" && trim(gNameObj.value) == "")
{
alert("Father/Guardian is mandatory!");
return false;
}
return true;
}
catch(e)
{
alert(e);
return false;
}
}
</script>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
--
Thanks&Regards
KIRAN