+ Start a Discussion
David WalsheDavid Walshe 

Question on Onclick Javascript - Getting error "Unexpected token ;"

Hi,

I am trying to a button using Javascript which uses a variable determined by whether the user has selected either standard or premium support.
However, I keep getting "Unexpected token ;". Any help is appreciated. 

Here is the script I am using:

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}

var cost;

if ({!ISPICKVAL(Quote.S_W_Support_Level__c , 'Premium')}) { 
cost = {!Quote.S_W_Premium_Maintenance__c};
} else {
cost = {!Quote.S_W_Standard_Maintenance__c};
Best Answer chosen by David Walshe
Prafull G.Prafull G.
enclose your fiel with single quotes should do it.
like
cost = '{!Quote.S_W_Premium_Maintenance__c}';

All Answers

Gaurav KheterpalGaurav Kheterpal
Remove the ; from these lines and I think it should fix it.
cost = {!Quote.S_W_Premium_Maintenance__c};
cost = {!Quote.S_W_Standard_Maintenance__c};
 
David WalsheDavid Walshe
Thanks Gaurav,

It now returns the error "Unexpected token }". 

If I use the following it works correctly when "Premium" is selected, however I get the unexpected token when Standard is selected.

if ({!ISPICKVAL(Quote.S_W_Support_Level__c , 'Premium')}) { 
cost =  {!TEXT(Quote.S_W_Premium_Maintenance__c)};
} else {
cost = '2345';


There appears to be a problem when using two different variables in the if-else statement.
 
Prafull G.Prafull G.
enclose your fiel with single quotes should do it.
like
cost = '{!Quote.S_W_Premium_Maintenance__c}';
This was selected as the best answer
David WalsheDavid Walshe
Thanks Prafull, single quotes resolved the issue.

Regards

David