+ Start a Discussion
Jim MontgomeryJim Montgomery 

Need to invoke javascript on visualforce page load, and redirect back to original page after execution

Here is my code, but it does not fire.

apex:page standardController="Opportunity"> <script src="/soap/ajax/10.0/connection.js"> </script > <script src="/soap/ajax/10.0/apex.js"> </script > <body onload="init()"/> <script type="text/javascript"> Function init() { alert("1") } { var p = new sforce.SObject('opportunity'); p.id = document.getElementById; var fulldate = (today.getMonth()+1)+'/'+today.getDate()+'/'+today.getFullYear(); var OppDateRaw = (new Date('{p.CloseDate}')); var formattedOppDate = (OppDateRaw.getMonth()+1) + '/'+OppDateRaw.getDate()+'/'+OppDateRaw.getFullYear(); if( formattedOppDate < fulldate) { alert("Close date cannot be in the past"); } else { if("{p.AMS_Order_Processing_Stage__c}" === "Approved" ) { p.AMS_Order_Processing_Stage__c = "Submitted to Order Processing"; result = sforce.connection.update([p]); location.reload(true); } else { alert("This opportunity has not been approved."); } } } window.history.back() } </script> </apex:page>
Best Answer chosen by Jim Montgomery
bob_buzzardbob_buzzard
JavaScript is case sensitive, so assuming this is an accurate cut and paste, your declaration of init is invalid due to the capital F :
Function init()
should be 
function init()


 

All Answers

bob_buzzardbob_buzzard
JavaScript is case sensitive, so assuming this is an accurate cut and paste, your declaration of init is invalid due to the capital F :
Function init()
should be 
function init()


 
This was selected as the best answer
Jim MontgomeryJim Montgomery
Thank you!! Jim Montgomery Manager, Sales Intelligence Operations Wolters Kluwer Tax & Accounting 20101 Hamilton Ave. Torrance, CA 90502 877-346-7148 jim.montgomery@wolterskluwer.com