You need to sign in to do that
Don't have an account?
Lukesh Karmore
i am not getting alert what"s the error
look at below code i put validation using javascript but it not throwing me error , i am unable to find error help me forum.
Thank you
public class insertcontact {
public string FirstName{get; set;}
public string LastName{get; set;}
public string Phone{get; set;}
public string Email{get; set;}
contact con=new contact();
public pagereference showcontact(){
con.FirstName=FirstName;
con.LastName=LastName;
con.Phone=Phone;
con.Email=Email;
insert con;
return null;
}
}
<apex:page controller="insertcontact" lightningStylesheets="true">
<apex:form id="EE" >
<apex:actionFunction name="callSave" action="{!showcontact}" reRender="out"/>
<apex:pageblock title="insert contact" id="AA" tabstyle="Account">
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Save" onclick="myfunction(); return false" />
</apex:pageBlockButtons>
<apex:pageblocksection id="xx">
<apex:outputLabel value="First Name"/>
<apex:inputtext value="{!FirstName}" />
<apex:outputLabel value="Last Name"/>
<apex:inputtext value="{!LastName}" />
<apex:outputLabel value="Email"/>
<apex:inputtext value="{!Email}" id="BB" />
<apex:outputLabel value="Phone"/>
<apex:inputtext value="{!Phone}" id="CC" />
<apex:outputPanel id="out">
{!FirstName} {!LastName}
{!Email}
{!Phone}
</apex:outputPanel>
</apex:pageblocksection>
</apex:pageblock>
<script type="text/javascript">
function myfunction(){
var Emailparam= document.getElementById('{!$Component.EE.AA.xx.BB}').value;
var Phoneparam= document.getElementById('{!$Component.EE.AA.xx.CC}').value;
if(Emailparam ==''||Phoneparam ==''){
Alert('Email and phone field is mandatary, take care of this');
}
else{
callSave(Emailparam,Phoneparam);
}
}
</script>
</apex:form>
</apex:page>
Thank you
public class insertcontact {
public string FirstName{get; set;}
public string LastName{get; set;}
public string Phone{get; set;}
public string Email{get; set;}
contact con=new contact();
public pagereference showcontact(){
con.FirstName=FirstName;
con.LastName=LastName;
con.Phone=Phone;
con.Email=Email;
insert con;
return null;
}
}
<apex:page controller="insertcontact" lightningStylesheets="true">
<apex:form id="EE" >
<apex:actionFunction name="callSave" action="{!showcontact}" reRender="out"/>
<apex:pageblock title="insert contact" id="AA" tabstyle="Account">
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Save" onclick="myfunction(); return false" />
</apex:pageBlockButtons>
<apex:pageblocksection id="xx">
<apex:outputLabel value="First Name"/>
<apex:inputtext value="{!FirstName}" />
<apex:outputLabel value="Last Name"/>
<apex:inputtext value="{!LastName}" />
<apex:outputLabel value="Email"/>
<apex:inputtext value="{!Email}" id="BB" />
<apex:outputLabel value="Phone"/>
<apex:inputtext value="{!Phone}" id="CC" />
<apex:outputPanel id="out">
{!FirstName} {!LastName}
{!Email}
{!Phone}
</apex:outputPanel>
</apex:pageblocksection>
</apex:pageblock>
<script type="text/javascript">
function myfunction(){
var Emailparam= document.getElementById('{!$Component.EE.AA.xx.BB}').value;
var Phoneparam= document.getElementById('{!$Component.EE.AA.xx.CC}').value;
if(Emailparam ==''||Phoneparam ==''){
Alert('Email and phone field is mandatary, take care of this');
}
else{
callSave(Emailparam,Phoneparam);
}
}
</script>
</apex:form>
</apex:page>
copy $ paste this following line .
alert('Email and phone field is mandatary, take care of this');
actually Alert's A was capital .
mark the best if it help you.
Thank you
yes, I work in jaipur.
Mark the best of this answer so that it can help to others in future.
Thank you
Hi Lukesh Karmore,
I have checked your code. Your code is correct. but you have one mistake in your code.
you have used the "Alert" function with "A" capital. but you have to use small 'a' for the alert function
like ='alert('Email and phone field is mandatary, take care of this');'
if you find this helpful mark it as the best answers.