Syntax as follows:
Where this is exactly fit in real time?
If you want to do a required field validation (making to enter/select for particular control as mandatory) for 10 pages, what you will do probably. The same validation needs to be fired in 10 webpages. We can avoid this by using calling external script.
1.Reusability since don’t need to place the code in HTML documents.
2.If there is a kind of change in validation then we don’t need to change code in all webpages.
3. It secures precious code.
Go to view ?source in browser your validation code can’t be seen .
Type the following code in note pad and save with extension as .js (external.js)
<script src ="external.js"></script>
<input type = "button" value ="click" onclick ="f();">
Where to Use script in the body or header?
A <script src="url"></script> blocks the downloading of other page components until the script has been identified, compiled, and executed. So It is better to call for the script as late as possible. If there are images or other components that will not be delayed. So it is usually best to make all <script src="url"></script> the last features before the </body>.
If a script is defining functions that are used by some other functions, then it is better to define it before use.