I have created onclick javascript button functionality but when I clicked on button I am getting "Problem with onclick javascript for this button or link was encountered: Invalid or Unexpected token". My code is


function post_to_url(path, method)
method = method || 'post'; // Set method to post by default, if not specified. 
var form = document.createElement('form'); 
form.setAttribute('method', method); 
form.setAttribute('action', path); 
form.setAttribute('target', '_blank'); 

var address1 =     

address1.replace(/\r?\n|\r/g, '');

var s1 = http://www.another_page.com &param=









post_to_url(s1, 'POST');

the Javascript is not valid as it's missing the quote ' at the start and you either need to have the string literal in one line or escape each line with \ at the end of the line.

You can see the fixed example of your code here:

var s1 = 'http://www.another_page.com&param={!URLENCODE(Account.IOG_Customer_ID__c)}%0D{!URLENCODE(Account.Website)}%0D{!URLENCODE(Account.Name)}%0D{!URLENCODE(Account.Billing_Contact_Street__c)}%0D{!URLENCODE(Account.Billing_Contact_City__c)%0D{!URLENCODE(Account.Billing_Contact_State__c)}%0D{!URLENCODE(Account.Billing_Contact_Zip__c)}%0D{!URLENCODE(Account.Phone)}';
| improve this answer | |
  • 2
    Please elaborate on the op’s problem/error rather than posting a corrected code dump with no explanation whatsoever so it may prove useful to others facing similar problems – glls Mar 17 '18 at 15:46
  • @glls I've stated "I don't think it's valid Javascript hence the error." How should I improve on this? – vladykx Mar 17 '18 at 16:19
  • for example, how is it not valid javascript syntax? – glls Mar 17 '18 at 16:24