You need to sign in to do that
Don't have an account?
chinu
Help me with javascript-How to display an error message using java script..
In the edit page when the picklist value is closed it should display an error message through popup by using java script.
you have to put alert message on javascript as per the condition.
see following sample example for your requirement.
Visualforce Page:
<apex:page>
<apex:form>
<script>
function validateJS(sel){
if(sel != null && sel.value == 'Closed'){
alert('Yor Error Message');
sel.value = 'Open';
}
}
</script>
<apex:selectList onchange="validateJS(this);" id="chooseColor" size="1">
<apex:selectOption itemValue="Open" itemLabel="Open"/>
<apex:selectOption itemValue="Closed" itemLabel="Closed"/>
</apex:selectList>
</apex:form>
</apex:page>
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
Email :- hiteshpatel.aspl@gmail.com
My Blog:- http://mrjavascript.blogspot.in/
Thank u so much for answering..please let me know how exactly i need to use your code in the below visualforce page code to work exactly
In the below code there is status picklist field.So when i will change the status field to closed then the popup message to be display.
<apex:page standardController="Account" extensions="StandardControllerwithExt">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{!Account.name}"/>
<apex:inputField value="{!Account.AnnualRevenue}"/>
<apex:inputField value="{!Account.Industry}"/>
<apex:inputField value="{!Account.Website}"/>
<apex:inputField value="{!Account.Active__c}"/>
<apex:inputField value="{!Account.SLA__c}"/>
<apex:inputField value="{!Account.UpsellOpportunity__c}"/>
<apex:inputField value="{!Account.Status__c}"/>
</apex:pageBlockSection>
<apex:pageblockButtons >
<apex:commandButton value="TestIt" action="{!Testit}"/>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageblockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks!!!
Please find the apex class related to visualforce page which i sent you in above.
public class StandardControllerwithExt {
public Account chkAccountValues;
public StandardControllerwithExt(ApexPages.StandardController controller) {
chkAccountValues=(Account)controller.getRecord();
}
public pagereference Testit()
{
Account varacc=new Account();
varacc.name=chkAccountValues.name;
varacc.AnnualRevenue=chkAccountValues.AnnualRevenue;
varacc.Industry=chkAccountValues.Industry;
varacc.Website=chkAccountValues.Website;
varacc.Active__c=chkAccountValues.Active__c;
varacc.SLA__c=chkAccountValues.SLA__c;
insert varacc;
pagereference redirect=new pagereference ('/'+varacc.id);
return redirect;
}
}
Thanks!!!
For your information i have not added status field in apex class in the above.
i.e.,
varacc.SLA__c=chkAccountValues.Status__c;
Thanks!!!