Java scripting embedded in HTML.

By: aathishankaran Viewed: 177 times  Printer Friendly Format    


HTML gives you the capability to create remarkable static Web pages. Although these documents have been creative, interesting, and by all means useful, JavaScript gives you the capability to make these extensive static pages interactive and more responsive to user actions and input. Extending your HTML pages with JavaScript puts more power to your page and gives you more flexibility with what your HTML can do. JavaScript cannot stand-alone but is always tied to your HTML page and the browser. JavaScript is an interpreted language that is processed by the browser when the page loads. 

JavaScript enables the Web developer to create pages that are more dynamic by embedding a scripting language in the existing HTML structure. You can now put processes behind buttons, run calculations on form-entered data, or perform actions when the user moves the mouse over an HTML object. 

JavaScript offers advantages over client-based interactive documents such as

CGI because JavaScript-based documents are less dependent on client-side processing, so they are quicker to respond to user interactions and requests. 

Embedding Script 

JavaScript scripts are integrated into HTML using the HTML<SCRIPT>and </SCRIPT>tags. Both the start and end tags are required for <SCRIPT>, and at the current time, the language attribute and source attribute are the only attributes currently available. Language is used to specify the scripting language in which the script is written, and source (SRC) is used to specify the filename of the JavaScript statements, if they are stored in a separate file. 

<SCRIPT LANGUAGE="JavaScript">

Script language

</SCRIPT>

EXAMPLE 

<SCRIPT LANGUAGE="JavaScript">

function options.()

{

document. write ("embedding the code")

}

</SCRIPT>

Method 2

<Script Language="JavaScript" For="Object" Event="onEvent()">

//Script coding

</Script>

EXAMPLE 

<Html>

<Head>

<Title>Example</Title>

<Script Language="JavaScript" For="window" Even t=" onLoad () ">

alert ("Hello") ;

<Script>

</Head>

<Body>

</Body>

</Html>

Method 3

<Script Language Scr="Filename.js">

</Script>

Example 

<SCRIPT SRC="myscript.js"> </SCRIPT>

Type the following code in a file called myscript.js

document. Write (“calling from a separate file")

When you load the script from another file, the Language attribute is not necessary as long as you use the correct.js extension. Using this methodology, you have the capability to modify your JavaScript code without ever opening and risking unwanted changes to your HTML pages. 

Generating HTML 

The example given below tells you to generate HTML pages from JavaScript. 

EXAMPLE

<Html>

<Head>

<Title>Using JavaScript to create HTML tags</Title>

</Head>

<Body>

<Script>

document.write("<Hl> Hi Web Surfers !!!</Hl>")

document.write ("<P>Welcome to <CITE>JavaScript</CITE></P>")

</Script>

</Body>

</Html>

Output 

Hi Web Surfers !!!

Welcome to JavaScript



Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial