Warning: include(/home/javarace/public_html/java8s.com/google/ad.php): failed to open stream: No such file or directory in /home/java8s/public_html/javascript/JavaScript-Introduction.php on line 58

Warning: include(/home/javarace/public_html/java8s.com/google/ad.php): failed to open stream: No such file or directory in /home/java8s/public_html/javascript/JavaScript-Introduction.php on line 58

Warning: include(): Failed opening '/home/javarace/public_html/java8s.com/google/ad.php' for inclusion (include_path='.:/opt/cpanel/ea-php56/root/usr/share/pear') in /home/java8s/public_html/javascript/JavaScript-Introduction.php on line 58
❮ Previous Next ❯

JavaScript Introduction

JavaScript is a scripting language of HTML which is very popular in the field of web application. It is used to represent dynamic content and works at the client side. There is a JavaScript translator which is embedded in browser(client) which translates the JavaScript code.
JavaScript can be used for:

JavaScript code is very simple to write. Basically we can put JavaScript code in 3 places, such as within head section, with in body section and within external JavaScript file.
Let's see our 1st JavaScript example:

<script type="text/javascript"> document.write("Welcome 2 java8s.com");

Here the script tag specifies that we are using JavaScript code in HTML. The text/javascript is the content type that provides information to the browser about the data. The document.write() function is used to display dynamic content through JavaScript. We will see about document object in later.

JavaScript code with in body tag:

<html>
<head></head>
<body>
<script type="text/javascript">
alert("java8s.com");
</script>
</body>
</html>

output:


JavaScript code within Head tag:

<html>
<head>
<script type="text/javascript">
function m1()
{
alert("welcome 2 java8s.com");
}
</script>
</head>
<body>
<b>Welcome to JavaScript</b>
<form>
<input type="button" value="click" onclick="m1()"/>
</form>
</body>
</html>

Output:




In the above example, displaying alert dialog box of JavaScript that is contained inside the head tag. Here ,we defined a function m1(). To call function, we need to work on event. Here we are using onclick event to call m1() function.
JavaScript code within external JavaScript file:
We can create external JavaScript file and embed it in many html page. It provides code re usability because single JavaScript file can be used in several html pages. Here external JavaScript file must be saved by .js extension. It is recommended to embed all JavaScript files into a single file.
We can create external JavaScript file and embed it in many html page. It provides code re usability because single JavaScript file can be used in several html pages. Here external JavaScript file must be saved by .js extension. It is recommended to embed all JavaScript files into a single file.

first.js:

function m1()
{
alert("Hii java8s.com");
}

test.html:

<html>
<head>
<script type="text/javascript" src="first.js"></script>
</head>
<body>
<p>Welcome to JavaScript</p>
<form>
<input type="button" value="click" onclick="m1()"/>
</form>
</body>
</html>
❮ Previous Next ❯



  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved