Welcome to S-Design
The home of your bespoke, professional, fast-loading, interactive, database-driven web presence.
Menu
JAVASCRIPT TUTORIALS


JAVASCRIPT Basics

JavaScript is a scripting language, just like PHP is. Javascript runs client-side (in the browser), whereas PHP is server-side (on the server which hosts the webpage).

There are 3 ways in which you can include JavaScript in your HTML: External, Included, and Inline
External JavaScript is JavaScript code that has been saved as a separate file (with .js extension).
Included JavaScript is JavaScript code that is physically written and included in the <head> of your HTML page.
Inline JavaScript is JavaScript code which is written into each HTML TAGs' onclick, onload, onmousedown etc.

And here's how you would link to an External JavaScript file: <html>
<head>
<title></title>
<script type="text/javascript" src="http://www.mywebsite.com/myjs.js"></script>
</head>
<body>
</body>
</html>

Here's an example of an Included Script: <html>
<head>
<title></title>
<script type="text/javascript">
Your JavaScript Goes Here
</script>
</head>
<body>
</body>
</html>

Here's an example of an Inline Script: <html>
<head>
<title></title>
</head>
<body onload="alert('document has loaded');">
</body>
</html>

The preferred method is External, for many reasons. It keeps your JavaScript completely outside and separate from your HTML, and if you should ever need to alter your code, you only have to edit one file, and the change will automatically apply to any HTML page linked to it. In other words... if you have 100 pages on your website, you would have to edit all 100 to make 1 small code change if your JavaScript was Included or Inline!

Title