20-12-2010
Eg: for alert pop up box:
<html>
<head>
<script type = "text/javascript">
function myfun()
{
alert("virtual memory is low")
}
</script>
</head>
<body>
<input type = "button" value = "Display" onclick = myfun()>
</body>
</html>
Output: Virtual Memory is Low
Eg: for Confirm Box
<html>
<head>
<script type = "text/javascript">
function myfun()
{
confirm("Do you want to restart your computer")
}
</script>
</head>
<body>
<input type = "button" value = "Display" onclick = myfun()>
</body>
</html>
Output: Do you want to restart your computer
Eg: To pass a value to java script function:
<html>
<head>
<script type = "text/javascript">
function display(txt)
{
alert(txt)
}
</script>
</head>
<body>
<input type = "button" value = "Morning" onclick = "display(Good Morning)">
<input type = "button" value = "Evening" onclick = "display(Good Evening)">
</body>
</head>
</html>
document.write(): It is a java script command, it will display the given value on web page.
Here, document is a pre-defined object & write is a pre-defined method.
Write method will print the given value on web page.
Eg: for returning a value from Java script function
<html>
<head>
<script type = "text/javascript">
function add(a,b)
{
return a+b
}
</script>
</head>
<body>
<script type = "text/javascript">
document.write(add(10,5))
</script>
</body>
</html>
Output: 15