JavaScript Startup

Updated on 29 Feb 2012,
Published on 07 Mar 2008

For starting JavaScript you must know how to put the javascript code in HTML page. This is the first step of JavaScript startup. 

Syntax to include JavaScript

<script language="javascript" type="text/javascript">

    //--- javascript functions here

</script>

Where to put JavaScript in the HTML Page

There are 4 ways of writing or including the JavaScript in a HTML Page:

1. JavaScript in HTML Head.

2. JavaScript inside the HTML Body.

3. Inline JavaScript code.

4. External JavaScript source

JavaScript in HTML Head

To execute the JavaScript when user hits any event on the HTML page by clicking or any property change that calls the JavaScript function are included or written in the Head section of the HTML Page.

<html>
<head>
    <title>JavaScript Example</title>
    <script language="javascript" type="text/javascript">
        //--- javascript functions here
    </script>
</head>
<body>
</body>
</html>

JavaScript inside the HTML Body

To execute the JavaScript for generating dynamic content on page load it can be placed inside the Body of HTML page.

<html>
<head>
    <title>JavaScript Example</title>
</head>
<body>
    <script language="javascript" type="text/javascript">
        //--- javascript functions here
    </script>
</body>
</html>

Inline JavaScript code

Inline JavaScript code is used to handle small functions directly bound to any event e.g.: color change on mouse over-out.

External JavaScript source

You can include external javascripts. Javascript functions can be placed in the separate file that can be included in the HTML page.

Syntax
<script language="javascript" 
        type="text/javascript" 
        src="PATH OF EXTERNAL JAVASCRIPT">
</script>

Continue to next tutorial: Javascript Variables and Operators to learn about the syntax and use of variables in JavaScript.

0 Responses to "JavaScript Startup"
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email
  • HIRE EzineASP.Net Developers