Friday, August 16, 2013

JavaScript end line comments

<html>
<body>

<script type="text/javascript">
document.write("Hello"); // Write "Hello"
document.write(" Mahbub!"); // Write " Mahbub!"
</script>

</body>
</html>

Result

 

JavaScript external_js

<html>
<head>
<script src="myjs.js">
</script>
</head>
<body>
<input type="button" onClick="popup()" value="Click Me!">
</body>
</html>

Result

 

JavaScript for in statement

<html>
<body>
<script type="text/javascript">
var x;
var mycars = new Array();
mycars[0] = "Saab";
mycars[1] = "Volvo";
mycars[2] = "BMW";

for (x in mycars)
{
document.write(mycars[x] + "<br />");
}
</script>
</body>
</html>

Result


JavaScript for loop

<html>
<body>

<script type="text/javascript">
for (i = 0; i <= 5; i++)
{
document.write("The number is " + i);
document.write("<br />");
}
</script>

<p>Explanation:</p>

<p>This for loop starts with i=0.</p>

<p>As long as <b>i</b> is less than, or equal to 5, the loop will continue to run.</p>

<p><b>i</b> will increase by 1 each time the loop runs.</p>

</body>
</html>

Result


JavaScript functions

<html>
<head>
<script type="text/javascript">
function displaymessage()
{
alert("Hello World!");
}
</script>
</head>

<body>
<form>
<input type="button" value="Click me!" onClick="displaymessage()" />
</form>

<p>By pressing the button above, a function will be called. The function will alert a message.</p>

</body>
</html>

Result


JavaScript getDay method

<html>
<body>

<script type="text/javascript">

var d=new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

document.write("Today is " + weekday[d.getDay()]);

</script>

</body>
</html>

Result


JavaScript getTime method

<html>
<body>

<script type="text/javascript">
var d=new Date();
document.write(d.getTime() + " milliseconds since 1970/01/01");
</script>

</body>
</html>

Result

JavaScript hello

<html>
<body>

<script type="text/javascript">
document.write("Hello World!");
</script>

</body>
</html>

Result

 

Thursday, August 15, 2013

javascript hello2

<html>
<body>

<script type="text/javascript">
document.write("<h1>Hello World!</h1>");
</script>

</body>
</html>

result

 

javascript if else if else statement

<html>
<body>

<script type="text/javascript">
var d = new Date();
var time = d.getHours();
if (time<10)
{
document.write("<b>Good morning</b>");
}
else if (time>=10 && time<16)
{
document.write("<b>Good day</b>");
}
else
{
document.write("<b>Hello World!</b>");
}
</script>

<p>
This example demonstrates the if..else if...else statement.
</p>

</body>
</html>
result

javascriptif statement

<html>
<body>

<script type="text/javascript">
var d = new Date();
var time = d.getHours();

if (time < 10)
  {
  document.write("<b>Good morning</b>");
  }
</script>

<p>This example demonstrates the If statement.</p>
<p>If the time on your browser is less than 10, you will get a "Good morning" greeting.</p>

</body>
</html>

result


javascriptimage map 01

<html>

<body>
<img src ="planets.gif" width ="145" height ="126" alt="Planets" usemap="#planetmap" />

<map name="planetmap">
<area shape ="rect" coords ="0,0,82,126"
href ="sun.htm" target ="_blank" alt="Sun" />

<area shape ="circle" coords ="90,58,3"
href ="mercur.htm" target ="_blank" alt="Mercury" />

<area shape ="circle" coords ="124,58,8"
href ="venus.htm" target ="_blank" alt="Venus" />
</map>

</body>
</html>

result


javascript image map 02

<html>
<head>
<script type="text/javascript">
function writeText(txt)
{
document.getElementById("desc").innerHTML=txt;
}
</script>
</head>

<body>
<img src ="planets.gif" width ="145" height ="126" alt="Planets" usemap="#planetmap" />

<map name="planetmap">
<area shape ="rect" coords ="0,0,82,126"
onMouseOver="writeText('The Sun and the gas giant planets like Jupiter are by far the largest objects in our Solar System.')"
href ="sun.htm" target ="_blank" alt="Sun" />

<area shape ="circle" coords ="90,58,3"
onMouseOver="writeText('The planet Mercury is very difficult to study from the Earth because it is always so close to the Sun.')"
href ="mercur.htm" target ="_blank" alt="Mercury" />

<area shape ="circle" coords ="124,58,8"
onMouseOver="writeText('Until the 1960s, Venus was often considered a  twin sister to the Earth because Venus is the nearest planet to us, and because the two planets seem to share many characteristics.')"
href ="venus.htm" target ="_blank" alt="Venus" />
</map>

<p id="desc"></p>

</body>
</html>

result


javascript index Of method

<html>
<body>

<script type="text/javascript">
var str="Hello world!";
document.write(str.indexOf("Hello") + "<br />");
document.write(str.indexOf("WORLD") + "<br />");
document.write(str.indexOf("world"));
</script>

</body>
</html>

result


javaScript animation

<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.getElementById("b1").src ="b_blue.gif";
}
function mouseOut()
{
document.getElementById("b1").src ="b_pink.gif";
}
</script>
</head>

<body>
<a href="http://www.systechdigital.com " target="_blank">
<img border="0" alt="Visit Systech Digital Ltd.!" src="b_pink.gif" id="b1" width="26" height="26" onMouseOver="mouseOver()" onMouseOut="mouseOut()" /></a>
</body>
</html>

result