You need to sign in to do that
Don't have an account?
John Braun
How to create onclick javascript button that won't fail when user inputs certain characters?
Hey community,
I have a Onclick javascript button that works except for the fact that it will fail if the user inputs an "illegal" character. For example, if in one of the fields the Onclick Javacript button is evaluating has a "$" symbol, it will return an error prompt saying "Illegal token". This is not good! Thanks for any help!!
Button below:
if ( '{!Opportunity.Active__c}' == '')
{alert('In order to request a Quote, ensure that "Active" is populated on the Opportunity record.'); }
else if ('{!Opportunity.Rx_OTC__c}' == '')
{alert('In order to request a Quote, ensure that "Product Type" is populated on the Opportunity record.'); }
else if ('{!Opportunity.Reason_to_Outsource__c}' == '')
{alert('In order to request a Quote, you must ensure that "Reason to Outsource" is populated on the Opportunity record.'); }
else if ('{!Opportunity.Key_Criteria_for_Sucessful_Bid__c}' == '') {alert('In order to request a Quote, you must ensure that "Key Criteria for Successful Bid" is populated on the Opportunity record.'); }
else if ('{!Opportunity.Price_Sensitivity_Target_Pricing__c}' == '') {alert('In order to request a Quote, you must ensure that "Pricing Guidance & Funding Situation" is populated on the Opportunity record.'); }
else if ('{!Opportunity.Involves_BLS__c}' == '') {alert('In order to request a Quote, you must ensure that "Involves BLS" is populated on the Opportunity record.'); }
else { window.location = "/0Q0/e?&oppid={!Opportunity.Id}&ent=Quote&Name='Placeholder'&ent=Quote &RecordType={!Opportunity.Quote_Record_Type__c} &retURL=/{!Opportunity.Id}"; }
I have a Onclick javascript button that works except for the fact that it will fail if the user inputs an "illegal" character. For example, if in one of the fields the Onclick Javacript button is evaluating has a "$" symbol, it will return an error prompt saying "Illegal token". This is not good! Thanks for any help!!
Button below:
if ( '{!Opportunity.Active__c}' == '')
{alert('In order to request a Quote, ensure that "Active" is populated on the Opportunity record.'); }
else if ('{!Opportunity.Rx_OTC__c}' == '')
{alert('In order to request a Quote, ensure that "Product Type" is populated on the Opportunity record.'); }
else if ('{!Opportunity.Reason_to_Outsource__c}' == '')
{alert('In order to request a Quote, you must ensure that "Reason to Outsource" is populated on the Opportunity record.'); }
else if ('{!Opportunity.Key_Criteria_for_Sucessful_Bid__c}' == '') {alert('In order to request a Quote, you must ensure that "Key Criteria for Successful Bid" is populated on the Opportunity record.'); }
else if ('{!Opportunity.Price_Sensitivity_Target_Pricing__c}' == '') {alert('In order to request a Quote, you must ensure that "Pricing Guidance & Funding Situation" is populated on the Opportunity record.'); }
else if ('{!Opportunity.Involves_BLS__c}' == '') {alert('In order to request a Quote, you must ensure that "Involves BLS" is populated on the Opportunity record.'); }
else { window.location = "/0Q0/e?&oppid={!Opportunity.Id}&ent=Quote&Name='Placeholder'&ent=Quote &RecordType={!Opportunity.Quote_Record_Type__c} &retURL=/{!Opportunity.Id}"; }
Hi John,
Please create a webservice method and put your entire logic in this webservice apex Method. And one benifit of webservice method is you can call it from javascript.
Hope above hints will help you.
Regards
AMUL
Thank you for the suggestion -
Is there anyway to correct this problem just in the button itself or is this the only option?
if ( '{!JSENCODE(Opportunity.Active__c)}' == '')
{alert('In order to request a Quote, ensure that "Active" is populated on the Opportunity record.'); }
else if ('{!Opportunity.Rx_OTC__c}' == '')
{alert('In order to request a Quote, ensure that "Product Type" is populated on the Opportunity record.'); }
else if ('{!JSENCODE(Opportunity.Reason_to_Outsource__c)}' == '')
{alert('In order to request a Quote, you must ensure that "Reason to Outsource" is populated on the Opportunity record.'); }
else if ('{!JSENCODE(Opportunity.Key_Criteria_for_Sucessful_Bid__c)}' == '') {alert('In order to request a Quote, you must ensure that "Key Criteria for Successful Bid" is populated on the Opportunity record.'); }
else if ('{!JSENCODE(Opportunity.Price_Sensitivity_Target_Pricing__c)}' == '') {alert('In order to request a Quote, you must ensure that "Pricing Guidance & Funding Situation" is populated on the Opportunity record.'); }
else if ('{Opportunity.Involves_BLS__c}' == '') {alert('In order to request a Quote, you must ensure that "Involves BLS" is populated on the Opportunity record.'); }
else { window.location = "/0Q0/e?&oppid={!Opportunity.Id}&ent=Quote&Name='Placeholder'&ent=Quote &RecordType={!Opportunity.Quote_Record_Type__c} &retURL=/{!Opportunity.Id}"; }