Exp 4
Exp 4
Alert Box
An alert box is often used if you want to make sure information comes through to the user.
When an alert box pops up, the user will have to click "OK" to proceed.
Syntax
alert("sometext");
Confirm Box
A confirm box is often used if you want the user to verify or accept something.
When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed.
If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false.
confirm("sometext");
Prompt Box
A prompt box is often used if you want the user to input a value before entering a page.
When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed
after entering an input value.
If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box
returns null.
prompt("sometext","defaultText");
a) Input: Click on Display Date button using onclick( ) function Output: Display
date in the textbox
<html>
<body bgcolor="#ACC8E6">
<title>DATE</title>
<script>
function display()
var date=d.getDate();
var month=d.getMonth();
month++;
var year=d.getFullYear()
document.getElementById("dis").value=date+"/"+month+"/"+year;
</script>
<form>
<center> <br>
</center>
</form>
</body>
</html>
b) Input: A number n obtained using prompt Output: Factorial of n number using alert
<html>
<head>
<title>
Factorial
</title>
</head>
<script language='javascript'>
function factorialcalc()
let factorial = 1
for(i=1;i<=number;i++)
factorial=factorial*i
</script>
<body>
<form name="form">
</form>
</body>
</html>
c) Input: A number n obtained using prompt Output: A multiplication table of numbers
from 1 to 10 of n using alert
<html>
<head>
</head>
<body>
<script type="text/javascript">
if(!isNaN(n))
var table="";
var number="";
for(i=1;i<=10;i++)
number = n * i;
alert(table);
else
</script>
</body> </html>
<html>
<head>
<script language='javascript'>
function addsum()
var sumofnums = 0
while (keepgoing)
</script>
</head>
<body>
<form name=frm>
</form>
</body>
</html>