Java scripting embedded in HTML.

By: aathishankaran Emailed: 1765 times Printed: 2515 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

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


Java Home | All Java Tutorials | Latest Java Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by aathishankaran
Web Security Issues
The Web User's Perspective
Server-side plug-Ins
The best way to avoid security vulnerabilities with new server
JavaScript Security
Window Object
Working with Status Bar Messages
Retrieving a Portion of a String
Referencing Windows
Math Object
Frame Object
Document Object
Closing Windows
Built-in Object in Javascript
Textarea Object

More Tutorials in Java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Java File
Java String
Count number of vowels, consonants and digits in a String in Java
Reverse a number in Java
Student marks calculation program in Java
Handling Fractions in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java
Multiple Inheritance sample in Java
Java program using Method Overriding
Java program to check if user input is an even number

More Latest News
Most Viewed Articles (in Java )
A Serialization Example in Java
Type Casting in Java
instanceof sample program in Java
FilenameFilter - sample program in Java
Using One-Dimensional Arrays in Java
Method Overriding in Java
indexOf( ) and lastIndexOf( ) in Java
The java Buzzwords
Write to a file in Java - Sample Program
What is Java?
FileReader and FileWriter example program in Java
A Tutorial on importing packages in Java
How to use ArrayList in Java
Extract characters in Java
XML and Java - Parsing XML using Java Tutorial
Most Emailed Articles (in Java)
Converting a number into its equalant value in words in Java
java.lang.reflect package
Disadvantages of using Native methods in Java
What is UCS? What is ISO 10646?
Generating Your Key Pair example using keytool in Java
Operator Precedence in Java
PushbackReader sample program in Java
concat(), replace(), and trim() Strings in Java
instanceof sample program in Java
Use of - new - in Java
The Benefits of OOP
Increment and Decrement Operator
Characters in java
The continuing Revolution of java
Why java is important to the Internet