simpel java script hand-out

<html>

<body>

<script type=”text/javascript”>

document.write(“Hello World!”);

</script>

</body>

</html>

HELLO WORLD

<html>

<body>

<script type=”text/javascript”>

document.write(“<h1>This is a header</h1>”);

</script>

</body>

</html>

THIS IS HEADER

<html>

<head>

</head>

<body>

<script type=”text/javascript”>

document.write(“This message is written by JavaScript”);

</script>

</body>

</html>

<html>

<head>

<script type=”text/javascript”>

function message()

{

alert(“This alert box was called with the onload event”);

}

</script>

</head>

<body onload=”message()”>

</body>

</html>

 

<html>

<head>

<script type=”text/javascript”>

function disp_alert()

{

alert(“I am an alert box!!”);

}

</script>

</head>

<body>

<input type=”button” onclick=”disp_alert()” value=”Display alert box” />

</body>

</html>

 

<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>

 

<html>

<head>

<script type=”text/javascript”>

function disp_confirm()

{

var r=confirm(“Press a button”);

if (r==true)

{

document.write(“You pressed OK!”);

}

else

{

document.write(“You pressed Cancel!”);

}

}

</script>

</head>

<body>

<input type=”button” onclick=”disp_confirm()” value=”Display a confirm box” />

</body>

</html>

 

<html>

<head>

<script type=”text/javascript”>

function disp_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=”disp_prompt()” value=”Display a prompt box” />

</body>

</html>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s