Javascript Examples
Javascript Examples
<html>
<body>
<html>
<body>
<script type="text/javascript">
var d = new Date();
var time = d.getHours();
<script type="text/javascript">
document.write("<p>" + Date() + "</p>");
</script>
</body>
</html>
ALERT BOX
<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert("Hello! I am an alert box!");
}
</script>
</head>
<body>
<input type="button" onclick="show_alert()" value="Show
alert box" />
</body>
</html>
</body>
</html>
ALERT BOX WITH LINE BREAK
<html>
<head>
<script type="text/javascript">
function disp_alert()
{
alert("Hello again! This is how we" + '\n' + "add line breaks to
an alert box!");
}
</script>
</head>
<body>
<input type="button" onclick="disp_alert()" value="Display
alert box" />
</body>
</html>
CONFIRM BOX
<html>
<head>
<script type="text/javascript">
function show_confirm()
{
var r=confirm("Press a button!");
if (r==true)
{
alert("You pressed OK!");
}
else
{
alert("You pressed Cancel!");
}
}
</script>
</head>
<body>
<input type="button" onclick="show_confirm()" value="Show
a confirm box" />
</body>
</html>
PROMPT BOX
<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name=prompt("Please enter your name","Harry Potter");
if (name!=null && name!="")
{
document.write("Hello " + name + "! How are you today?");
}
}
</script>
</head>
<body>
<input type="button" onclick="show_prompt()" value="Show
prompt box" />
</body>
</html>