The CreatorCon Call for Content is officially open! Get started here.

wrapped in a function

johnrob18
Giga Guru

Note

Note: If the UI action is enabled to run on the client side, it should be wrapped in a function. Otherwise, the contents of the Script field executes on page load.
4 REPLIES 4

johnrob18
Giga Guru

I am not sure what this means - I currently have the issue that when I use the 'add attachment' UI that is a tthe bottom of my screen, it clears out all the fields that have been completed on the change record.



Strangely the same   UI action at he top of the screen works perfectly.


casey_stinnett
Giga Expert

The way that client side code works is that when a page loads, any code that is set up to be called, will be called. Whatever code is not wrapped in a function will be called on page load. When you wrap your code in a function, then you are telling the browser that it shouldn't run the code until that specific function is called.



Runs every time:



alert('I run on page load!');



Runs every time:



callAlert();



function callAlert(){


    alert('I run on page load!');


}



Runs only when you call it from elsewhere:



function callAlert(){


    alert('I do not run on page load!');


}



Does that help?


Casey, thanks - I have sorted the probelm . John


Awesome! Will you either post the solution or mark a reply as the right answer? That way it will close off this thread and give guidance to those who will read this in the future.