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

Help on Javascript button code
I have a situation where I am trying to check when the country(picklist) is "United States" or "Mexico" or "Brazil", the state cannot be blank.
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js')}
country = '{!JSENCODE(TEXT(Account.Country__c))}';
state ='{!JSENCODE(TEXT(Account.State__c))}';
if (state != "" && !!(country=='United States' || country=='Mexico' || country=='Brazil')){
continue with the process}
}else
alert('State is required for conversion of this account.');
My condition is throwing me alert even if my country is not any of these.
Thanks in advance.
Aruna
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js')}
country = '{!JSENCODE(TEXT(Account.Country__c))}';
state ='{!JSENCODE(TEXT(Account.State__c))}';
if (state != "" && !!(country=='United States' || country=='Mexico' || country=='Brazil')){
continue with the process}
}else
alert('State is required for conversion of this account.');
My condition is throwing me alert even if my country is not any of these.
Thanks in advance.
Aruna
All Answers
I still see the same issue.
Country and State both are picklist values which contain some special characters, so to avoid errors I am using JSENCODE
In the same button, I am also checking for various conditions where I have to see that TaxId cannot be blank for a list of countries.
if (!(taxid == '' && (country == 'Netherlands Antilles' || country == 'Austria' || country == 'Belgium' || country == 'Bulgaria' || country == 'Cyprus' || country == 'Czech Republic' || country == 'Germany' || country == 'Denmark' || country == 'Estonia' || country == 'Spain' || country == 'Finland' || country == 'France' || country == 'United Kingdom' || country == 'French Guiana' || country == 'Greece' || country == 'Croatia' || country == 'Hungary' || country == 'Ireland' || country == 'Italy' || country == 'Lithuania' || country == 'Luxembourg' || country == 'Latvia' || country == 'Malta' || country == 'Netherlands' || country == 'Poland' || country == 'Portugal' || country == 'Romania' || country == 'Sweden' || country == 'Slovenia')))
Is there a better way I can write this condition.
Thanks in advance