Function in one js file can't find the js file in another?

Hi

I have the following code in one js file:

one.js
    function check_holiday (dt_date){
	var holidays = {
	    2015:[[5,25],[8,31],[12,24],[12,25],[12,26],[12,27],[12,28],[12,29],[12,30],[12,31]],
	    2016:[[1,1],[3,25],[3,28],[5,2],[5,30],[8,29],[12,26],[12,27],[12,28],[12,29],[12,30],[12,31]],
	    2017:[[1,1],[1,2],[1,3]]
	};
			
	for(;;){
	    var hol_array = holidays[dt_date.getFullYear()];
	    if( hol_array ){
		var is_hol = false;
		for( var i in hol_array ){
		    var hol = hol_array[i];
		    if( ( hol[0] == dt_date.getMonth()+1 && hol[1] == dt_date.getDate()) || ( dt_date.getDay() == 0 || dt_date.getDay() == 6 ) ) // Skip weekends
		    {
			    is_hol = true;
			    dt_date.setDate(dt_date.getDate()+1);
			    break;
		    }
		}
		if( !is_hol ){
		    break;
		}
	    }
	}
	return dt_date;
    };			
    

Open in new window


and i'm calling it in another js file:

two.js
var futureDate = check_holiday(date_time);

Open in new window


I see the following error in Firebug:
error from Firebug in Firefox
Hope you can help
LVL 1
ACEAFTYAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,
have you referenced the files in your source code in the right order?
First the file with the function and then the second file where you call it.
HTH
Rainer

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ACEAFTYAuthor Commented:
Yes I have one.js in the header and two.js inserted at the bottom of the body tag.
Rainer JeschorCommented:
Hi,
as this works, it must be something either in one of your JS files or in the HTML file.
Could you please attach the three files?
Do you use any namespace in one.js?
Thanks.
Rainer
Rainer JeschorCommented:
And here my local sample which runs on my test IIS site successfully.

Whats your web server? Are you using any server side code (PHP, ASP, ASP.NET ...)?
EESampleJSRefError.zip
ACEAFTYAuthor Commented:
Hi
As I was getting the files ready to send to you and I reallised the problem. The one.js had

var $ = jQuery.noConflict();      
jQuery(document).ready(function($){

and the function was within this, so wasn't accessible globally. I didn't see because it wasn't at the beginning of the document as you'd expect it to be.

Technically your answer is correct you i'll accept your solutions.

Thank you for the time to trying to help me.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.