Skip to main content

Javascript


*the extension name of javascript is .html
*for variable var
*to convert number to text is eval
*alert - light message box
*prompt- input box


LIST                
*three types of list are there
 1) order list   2)Unorder list  3)Defination list

1) order list:- order list are five types:- ABCD....., abcd....., 1234...., i ii iii iv..., I II III IV...
2) Unorder list:- Unorder list are three types:-   cicrle, disc, square

Addition of two numbers 

<html>
  <head>
        <title>Addition of two numbers</title>
        <script language="javascript">
                function addNumbers()
                {
                        var val1 = parseInt(document.getElementById("value1").value);
                        var val2 = parseInt(document.getElementById("value2").value);
                        var ansD = document.getElementById("answer");
                        ansD.value = val1 + val2;
                }
        </script>
  </head>
  <body>
        value1 = <input type="text" id="value1" name="value1" value="0"/>
        value2 = <input type="text" id="value2" name="value2" value="0"/>
        <input type="button" name="Sumbit" value="Sum" onclick="javascript:addNumbers()"/>
        Answer = <input type="text" id="answer" name="answer" value="0"/>
  </body>
</html>

Alert

<html>
<head><title>Alert</title>
<script language="javascript">
function gm()
{
alert("good morning")
}
function th()
{
alert("thank you")
}
</script>
</head>
<body onload="gm()" onunload="th()">
<p>Close this window or press F5 to reload the page for  <strong>onunload</strong>.</p>
<p><strong>Note:</strong> Due to different browser settings, <strong>onunload</strong> event may not always work as expected.</p>
</body>
</html>

Password

<html>
<head><title>check password</title>
<script language="Javascript">
function pw()
{
var a=f1.t1.value;
var b=f1.t2.value;

if(a=="bappasaikh1994")
if(b=="7908751712")
{
open("https://www.youtube.com/bappasaikh");
}
else
{
alert("check password");
}
else
{
alert("check username");
}
}
</script>
</head>
<body>
<form name="f1">
enter username:- <input type="text" name="t1" value=""><br>
enter password:- <input type="password" name="t2" value=""><br>
          <input type="button" name="b1" value="OK" onclick="pw()">
</form>
</body>
</html>

Color Changing Button

<html>
<head><title>color Changinging button</title>
<script language="Javascript">
function r()
{
document.bgColor="red"
}
function g()
{
document.bgColor="green"
}
function y()
{
document.bgColor="yellow"
}
</script>

</head>
<body>
<form name="f1">
<input type="button" name="b1" value="red" onclick="r()">
<input type="button" name="b2" value="green" onclick="g()">
<input type="button" name="b3" value="yellow" onclick="y()">
</form>
</body>
</html>

Maximum

<html>
<head><title>Maximum between two numbers</title>
<script language="javascript">
function mx()
{
var a;
var b;
a=eval(a);
b=eval(b);
a=prompt("enter your 1st no:-");
b=prompt("enter your 2nd no:-");
if(a>b)
{
alert(a);
}
else
{
alert(b);
}
}
</script>
</html>
<body onload="mx()">
</body>
</html>

Odd/Even

<html>
<head><title>odd or even</title>
<script language="Javascript">
function oe()
{
var a;
a=prompt("enter your no:-");
if(a%2==0)
{
alert("even")
}
else
{
alert("odd")
}
}
</script>
</head>
<body onload="oe()">
</body>
</html>

Prompt

<html>
<head><title>Prompt</title></head>
<script language="Javascript">
function sum()
{
var a;
var b;
var c;
a=prompt("enter 1st no:-");
b=prompt("enter 2nd no:-");
c=eval(a)+eval(b)
alert(c)
}
</script>
</head>
<body onload="sum()">
</body>
</html>

Voter non voter

<html>
<html>
<head><title>voter or non voter</title>
<script language="javascript">
function vn()
{
var a
a=prompt("enter your age")
if(a>=18)
{
alert("voter")
}
else
{
alert("non Voter")
}
}
</script>
</head>
<body onload="vn()">
</body>
</html>

Comments