Link to home
Start Free TrialLog in
Avatar of ACEAFTY
ACEAFTYFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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:
User generated image
Hope you can help
ASKER CERTIFIED SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ACEAFTY

ASKER

Yes I have one.js in the header and two.js inserted at the bottom of the body tag.
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
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
Avatar of ACEAFTY

ASKER

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.