Way of Using JavaScript

Google Advertisements

Prev Tutorial Next Tutorial

Way of Using JavaScript

There are three places to put the JavaScript code.

  • Between the <body> </body> tag of html (Inline JavaScript)
  • Between the <head> </head> tag of html (Internal JavaScript)
  • In .js file (External JavaScript)

Inline JavaScript

When java script was written within the html element using attributes related to events of the element then it is called as inline java script.

Example of Inline JavaScript

Example How to use JavaScript

<html>
<form>
<input type="button" value="Click" onclick="alert('Button Clicked')"/>
</form>
</html>

Result

Internal JavaScript

When java script was written within the section using element then it is called as internal java script.

Example of Internal JavaScript

Example

<html>
<head> 
<script>
function msg()
{
alert("Welcome in JavaScript");
}
</script>
</head>
<form>
<input type="button" value="Click" onclick="msg()"/>
</form>
</html>

Result

External JavaScript

Writing java script in a separate file with extension .js is called as external java script. For adding the reference of an external java script file to your html page, use tag with src attribute as follows

Example

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

Create a file with name functions.js and write the following java script functions in it.

message.js

Example

function msg()
{  
 alert("Welcome in JavaScript");  
}  

Create a html page and use the file functions.js as follows

index.html

Example

<html>  
<head>  
<script type="text/javascript" src="message.js"></script>  
</head>  
<body>  
<form>  
<input type="button" value="click" onclick="msg()"/>  
</form>  
</body>  
</html>  

Result


Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. If you want to post your article on our website/FB Group/FB Page please contact on hitesh.xc@gmail.com or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders.

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar.

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user.

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects.

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483