PDA

View Full Version : global functions



ggalan
01-14-2011, 04:42 PM
is it possible to call a function from a different JS file?
lets say in my header i have 2 different files, can i call a function that resides in "main_2.js" from 'main_1.js'
?


<script type="text/javascript" src="js/main_1.js"></script>
<script type="text/javascript" src="js/main_2.js"></script>

Oziam
01-14-2011, 07:51 PM
In a word, YES,

e.g I have an AJAX formpost script, and a form fieldcheck(sanitizer)
script, when a user submits the form it calls a function from the fieldcheck
script and if it passes the check it then calls a function from the formpost script to process the form!

Cheers!

traq
01-14-2011, 08:39 PM
just make sure the file the function is in is already loaded before the other script calls it.

Oziam
01-14-2011, 11:54 PM
just make sure the file the function is in is already loaded before the other script calls it.

Yes traq execellent point I neglected to mention, otherwise you will get "Object expected" error message.