Home
XHTML
CSS
PHP
MySQL
SEO
JavaScript
Computer Basics
Number Systems
LINUX


JavaScript Tutorials

JavaScript | Programming | Decisions | Objects

JavaScript is a scripting language for advanced webpage design and interactive features. JavaScript is an object-oriented programming language. A JavaScript file is a plain text file named with a .js extension.

External JavaScript is coded in a separate file with a .js extension. The JavaScript file is called by the XHTML file. The link reference is declared within the header element of the XHTML file. The <script> and </script> tags declare the file type and link reference to the external JavaScript file. The following example calls a JavaScript function with an id name...

<html>
<head>
<title>Title of Webpage</title>

<script type="text/javascript" src="filename.js">
</script>

</head>
<body>

<p id="id">This is a paragraph.</p>

</body>
</html>





Internal JavaScript is coded directly in the XHTML file. Internal JavaScript is coded within the header element of the XHTML file, within the <script> and </script> tags. The CDATA code is not required, but added for cross-browser compatibility. The following example calls a JavaScript function with an id name...

<html>
<head>
<title>Title of Webpage</title>

<script type="text/javascript">
<!--//--><![CDATA[//><!--

functionName("id")

//--><!]]>
</script>

</head>
<body>

<p id="id">This is a paragraph.</p>

</body>
</html>


Internal JavaScript can also be coded within the body element of the XHTML file. The following example outputs a value to the browser...

<html>
<head>
<title>Title of Webpage</title>
</head>
<body>

<p>

<script type="text/javascript">
<!--//--><![CDATA[//><!--

document.write("This is a paragraph.");

//--><!]]>
</script>

</p>

</body>
</html>

The output to the browser is...

This is a paragraph.




Inline JavaScript is coded directly within the body element of the XHTML file, independent of any other references. The following example outputs an image in a new browser window with defined width and height attributes. Other various window attributes can be defined with a yes or no value...

<html>
<head>
<title>Title of Webpage</title>
</head>
<body>

<p>

<a href="javascript:location='javascript.php';
window.open('image.jpg', 'id', 'width=234,height=166,
location=yes,scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes')">
Click Here</a>

</p>

</body>
</html>

The output to the browser is...

Click Here




Comments can be added in JavaScript for notes or reminders. Comments are visible in the source code, but not the browser...

<script type="text/javascript">

// This is how to code a single line comment in JavaScript

/* This is how to code a single line
   or multiple line comment in JavaScript */

</script>


The <noscript> and </noscript> tags can be used to declare text as an option for browsers that do not understand JavaScript...

<noscript>
This text will appear if the browser does not understand JavaScript.
</noscript>



SEO Vancouver, Washington
SEO Portland, Oregon
Website Design Vancouver, Washington