js1

Share this page :

What is scripting language?

A scripting language is a programming language that allows controls of
one or more applications.

What Is JavaScript?
JavaScript is an object-based scripting language designed primarily for
author‘s constructing HTML documents for viewing under Google Chrome, Firefox,  Microsoft internet explorer and other compatible browser.

What is Variables?
JavaScript variables are “containers” for storing information.
Example:
var x = 5;
var y = 6;
var z = x + y;

A simple JavaScript program:

*Open Notepad & type the code.

<html>
<body>
<script>
document.write(“<u><center><h1>Welcome to JavaScript</center></h1></u>”);
document.write(“<H2>Scripting Language:</H2>”);
document.write(“<H4>A new world</H4>”);
</script>
</body>
</html>

*Save the file with “.html” extension.
*Open any browser(Internet Explorer/Opera/Mozilla)
*OR
*Right click on the file=>open with=>Internet Explorer

The “document.write” command is a standard JavaScript command for writing output to a page. By entering the “document.Write” command between the <script> and </script> tags. The browser will recognize it as a JavaScript command and execute the code line.

 

Background change:

<html>

<head>
<title>javascript</title>
</head>

<body>

<h1>Body Background color</h1>

<script>
document.bgColor=”yellow”;
</script>

</body>
</html>

 

Alert () :
The alert () function enables you to alert or inform the user about something by displaying a message box.

<html>
<head>
<title>alert box</title>
</head>
<body>
<script>
alert (“Welcome to JavaScript”);
</script>
</body>
</html>

confirm() :-
It displays the confirm dialog box containing message with ok and cancel button.
<html>
<body>
<script>
var s=confirm(“Are you ok?”);
if(s==true)
{
alert(“you pressed ok”);
}
else
{
alert(“you pressed cancel”);
}
</script>
</body>
</html>

 

prompt() :-
It displays a dialog box to get input from the user.
<html>
<body>
<script>
var k=prompt(“What is your name?”);
alert(“I am ” + k);
</script>
</body>
</html>

 

Accessing field value by document object:

In this example, we are going to get the value of input text by user. Here, we are using document.form1.name.value to get the value of name field.

<html>
<body>

<script>
function ns()
{
var name = document.form1.name.value;
alert(“Welcome: ” + name);
}
</script>

<form name=”form1″>

Enter Name:<input type=”text” name=”name”>

<input type=”button” onclick=”ns()” value=”click here”>

</form>

</body>
</html>

Click here

Share this page :