Link to home
Start Free TrialLog in
Avatar of prosoftsolutionsinc
prosoftsolutionsinc

asked on

Syntax to Include JS file in HTML code

What is the syntax to include a JS file in HTML code and then call functions within the JS file?

David
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark 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
where myfile.js could look like this:

8<--------------cut ------------
// Remember NO html tags in js files
function myFunctionFromJsFile() {
   alert('Hello from JS');
}
// end of js file
8<--------------cut ------------

Michel
Hi, as usual

Add the tag like this:

<SCRIPT LANGUAGE="JavaScript1.2" SRC="../include/js/mainArrays.js"></SCRIPT>


The mainArrays.js document:
_________________________________________________________
arMenu1 = new Array(
120,
144,122,
"","",
"","",
"","",
"Introduction","../petrol/petrol.htm",0,
"S2000 Product Specification","../petrol/S2000_pdt_specification.htm",0,
"E'MAX Technology","../petrol/Emax_tech.htm",0,
"Product Warranty","../petrol/pdt_warranty.htm",0,
"Product Liability","../petrol/pdt_liability.htm",0,
"Installation Procedure","#",0,
"Petrol Test Report","../petrol/TestReport.htm",0,
"Customer Reference","../petrol/customer_reference.htm",0
)


arMenu2 = new Array(
120,
144,140,
"","",
"","",
"","",
"Introduction","../diesel/diesel.htm",0,
"Product Specification","../diesel/pdt_specification.htm",0,
"E'MAX Technology","../diesel/Emax_tech.htm",0,
"Product Warranty","../diesel/pdt_warranty.htm",0,
"Product Liability","../diesel/pdt_liability.htm",0,
"Installation Procedure","#",0,
"Diesel Test Report","../diesel/TestReport.htm",0,
"Customer Reference","../diesel/customer_reference.htm",0
)

arMenu3 = new Array(
120,
144,158,
"","",
"","",
"","",
"Our Mission","../emax/mission.htm",0,
"Chairman's Message","../emax/chair.htm",0,
"About HQ","../emax/hq.htm",0,
"Japan Manufacturing Plant","../emax/mfg.htm",0,
"E'MAX Technology","../emax/Emax_tech.htm",0,
"Patents","../emax/patent.htm",0
)


arMenu4 = new Array(
120,
144,176,
"","",
"","",
"","",
"Air","../envt/air.htm",0,
"Air Pollution","../envt/pollute1.htm",0,
"Ozone & Smog","../envt/ozone1.htm",0,
"Global Warming","../envt/global1.htm",0,
"Climate Change","../envt/climate.htm",0,
"Carbon Cycle","../envt/carbon1.htm",0,
"Engine's Health & Environmental Impacts","../envt/engine_health.htm",0,
"Other Links","../envt/otherlinks.htm",0
)


__________________________________________________

View the website created from JScript.

www.emaxenv.com

Hope will help.
Hi  ryancys
Except for size, what is the difference between yours and my code???

Michel
Hi, mplungian.

Just post something i think correct, nothing else. Ignore my comment if needed.
Problem is that quite a number of people would say, hey the comments are the same - let's give the points to the largest post :( Happens all the time - so I tend not to post a similar post unless it is adding to the discussion...

Michel
mplungjan, ya, thanks for your advice. Maybe i'm too rush to post my comment.
Avatar of Netminder
Netminder

Deletion rejected. Force-accepted by

Netminder
Community Support Moderator
Experts Exchange