HTML & JavaScript

Examples of HTML objects that you interact with when using JavaScript are windows, text fields and images.

In the chart below, I have outlined the different tags used in HTML and the JavaScript that will accompany each when used together.

Two Choices

You have two choices when it comes to embedding JavaScript code in an HTML file:

  • You can use the <Script> and </Script> tag directly into the HTML page.
  • You can create an external file that has only JavaScript statements and contains a .js extension as opposed to an .html extension for an HTML document.

Example of JavaScript Directly Embedded in the HTML Document

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
// JavaScript code goes here //
}
</SCRIPT>
</HEAD>
<BODY>
...Somewhere within your body you will refer to a value you assigned within your JavaScript, such as what to do when an image appears.

</BODY>
</HTML>

Example of JavaScript With an External, Separate JavaScript File

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript" SRC="TheSeparateJSfile.js">
</SCRIPT>
</HEAD>
<BODY>

<A HREF="javascript:NameOfJavascriptValueWithinTheFile;">Please click here for XYZ ....</A>

</BODY>

</HTML>



Join the Discussion
Write something…
Recent messages
Mike-Writes Premium
Thanks for the great tutorial, Steph.
Reply
stephhill Premium Plus
Hi Mike. Good to see you. You are welcome!
Reply
Genie3733 Premium
Thanks but I think I'll save this. I'm just not ready for it yet. I'm too new and am trying to cram too many other bits of information in my brain.
Reply
stephhill Premium Plus
I totally understand. It will be here when you are ready. :)
Reply
AlexEvans Premium Plus
Thank you Steph, another link in the chain, very much appreciated.
Reply
stephhill Premium Plus
Thank you Alexander for checking it out.
Reply
Tirolith Premium
What ever you do is always very well done. Thanks from Tom.
Reply
stephhill Premium Plus
Thank you Tom!
Reply
Martstervt Premium
Will archive for later thanks.
Reply
stephhill Premium Plus
You are welcome!
Reply
Top