0

I'm trying to do something that should be very basic in SalseForce. I just need a button to run a small piece of javascript. It's throwing the following error at the moment "Invalid assignment left hand side error". Any help would be greatly appreciated.

if (  {!Contact.MailingPostalCode} =  'SC') {window.open('http://www.google.com','mywindow'); }

if (  {!Contact.MailingPostalCode}  =  'FL')  {window.open('http://www.yahoo.com','mywindow');  
}

Thanks

2
  • 1
    = means assignment. == means comparison. Commented Aug 8, 2012 at 20:23
  • @Zach Colon, As a clarification, you would like Google to pop up if the Postal Code is NOT 'SC', correct? And Yahoo if the Postal Cost is NOT 'FL'? Commented Aug 8, 2012 at 20:28

2 Answers 2

1

Your = needs to be ==. You are assigning and what you want to do is compare.

EDIT: Also, your 'not', !, may need to be on the outside. I'm not familiar with the SalesForce side.

EDIT 2: Try it this way:

if ({!Contact.MailingPostalCode} == 'SC') {
    window.open('http://www.google.com','mywindow');
}
if ({!Contact.MailingPostalCode} == 'FL') {
    window.open('http://www.yahoo.com','mywindow');
}

TESTING:

if ({!Contact.MailingPostalCode} == 'SC') {
    window.open('http://www.google.com','mywindow');
}
else if ({!Contact.MailingPostalCode} == 'FL') {
    window.open('http://www.yahoo.com','mywindow');
}
else {
    alert({!Contact.MailingPostalCode});
}

EDIT 3: For completeness, @Zach Colon's code is:

if ('{!Contact.MailingState}' == 'SC') {
    window.open('http://www.google.com','mywindow');
}
if ('{!Contact.MailingState}' == 'FL') {
    window.open('http://www.yahoo.com','mywindow');
} 
Sign up to request clarification or add additional context in comments.

7 Comments

Tried that too. Checked again just now. When I use '==' the button doesn't do anything period. No error, nothing.
@ZachColon, I gave some sample code. Try that. I think the '!' may have also been throwing things off.
It's a salesforce variable. Doesn't mean not in this example.
Ok, good clarification. The answers my comment under your original post.
@ZachColon, try the code I put under TESTING: and see what you get.
|
0

Do not forget the quotes for your SF variable '{!Contact.MailingPostalCode}':

if ('{!Contact.MailingPostalCode}' == 'SC') {
    window.open('http://www.google.com','mywindow'); 
}

if ('{!Contact.MailingPostalCode}' == 'FL'){
    window.open('http://www.yahoo.com','mywindow'); 
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.