javascript exp-5


<html>
<head>
<script type="text/javascript">
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout('startTime()',500);
}

function checkTime(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}
var c=0;
var t;
var timer_is_on=0;

function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",1000);
}

function doTimer()
{
if (!timer_is_on)
  {
  timer_is_on=1;
  timedCount();
  }
}

function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}
function timeMsg()
{
var t=setTimeout("alertMsg()",3000);
}
function alertMsg()
{
alert("Hello");
}
var i=0;
for (i=0;i<=5;i++)
{
document.write("The number is " + i);
document.write("<br />");
}
var txt="";
function message()
{
try
  {
  adddlert("Welcome guest!");
  }
catch(err)
  {
  txt="There was an error on this page.\n\n";
  txt+="Click OK to continue viewing this page,\n";
  txt+="or Cancel to return to the home page.\n\n";
  if(!confirm(txt))
    {
    document.location.href="#";
    }
  }
}

function show_alert()
{
alert("I am an alert box!");
}

function show_confirm()
{
var r=confirm("Press a button");
if (r==true)
  {
  alert("You pressed OK!");
  }
else
  {
  alert("You pressed Cancel!");
  }
}

function show_prompt()
{
var name=prompt("Please enter your name","vivek nayyar");
if (name!=null && name!="")
  {
  document.write("<p>Hello " + name + "! How are you today?</p>");
  }
}

var i;
var mycars = new Array();
mycars[0] = "Saab";
mycars[1] = "Volvo";
mycars[2] = "BMW";

for (i=0;i<mycars.length;i++)
{
document.write(mycars[i] + "<br />");
}

function myFunction()
{
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort();
var x=document.getElementById("demo");
x.innerHTML=fruits;
}
</script>
</head>


<body onload="startTime()">
<div id="txt"></div>
<pre>
<form>
<input type="button" value="Start count!" onclick="doTimer()" />
<input type="text" id="txt" />
<input type="button" value="Stop count!" onclick="stopCount()" />
</form>

<form>
<input type="button" value="Display alert box in 3 seconds"
onclick="timeMsg()" />
</form>


<input type="button" value="View message" onclick="message()" />

<input type="button" onclick="show_alert()" value="Show alert box" />

<input type="button" onclick="show_confirm()" value="Show confirm box" />

<input type="button" onclick="show_prompt()" value="Show prompt box" />
</pre>
</body>
</html>

Penulis : vivek nayyar ~ Sebuah blog yang menyediakan berbagai macam informasi

Artikel javascript exp-5 ini dipublish oleh vivek nayyar pada hari Monday, 9 April 2012. Semoga artikel ini dapat bermanfaat.Terimakasih atas kunjungan Anda silahkan tinggalkan komentar.sudah ada 0 komentar: di postingan javascript exp-5
 

0 comments:

Post a Comment