Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
30Activity
0 of .
Results for:
No results containing your search query
P. 1
Javascript

Javascript

Ratings:

4.5

(1)
|Views: 796|Likes:
Published by api-3722360

More info:

Published by: api-3722360 on Oct 15, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

Basic JavaScript
Write text with JavaScript

<html>
<body>
<script type="text/javascript">

document.write("Hello World!")

</script>
</body>
</html>

Format text with HTML tags

<html>
<body>
<script type="text/javascript">
document.write("<h1>Hello World!</h1>")
</script>
</body>
</html>

JavaScript in the head section

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

JavaScript in the body section

<html>
<head>
</head>
<body>
<script type="text/javascript">
document.write("This message is written when the page loads")
</script>
</body>
</html>

An external JavaScript

<html>
<head>
</head>
<body>
<script src="xxx.js">
</script>
<p>
The actual script is in an external script file called "xxx.js".
</p>
</body>
</html>

Declare a variable, assign a value to it, and display it

<html>
<body>
<script type="text/javascript">
var name = "Hege"
document.write(name)
document.write("<h1>"+name+"</h1>")
</script>
<p>This example declares a variable, assigns a value to it, and then displays the
variable.</p>
<p>Then the variable is displayed one more time, only this time as a heading.</p>
</body>
</html>

If statement

<html>
<body>
<script type="text/javascript">
var d = new Date()
var time = d.getHours()
if (time < 10)
{document.write("<b>Good morning</b>")

}</script>

<p>
This example demonstrates the If statement.
</p>
<p>
If the time on your browser is less than 10,
you will get a "Good morning" greeting.

</p>
</body>
</html>

If...else statement

<html>
<body>
<script type="text/javascript">
var d = new Date()
var time = d.getHours()
if (time < 10)
{document.write("<b>Good morning</b>")

}else
{document.write("<b>Good day</b>")
}</script>

<p>
This example demonstrates the If...Else statement.
</p>
<p>
If the time on your browser is less than 10,
you will get a "Good morning" greeting.
Otherwise you will get a "Good day" greeting.
</p>
</body>
</html>

Random link

<html>
<body>
<script type="text/javascript">
var r=Math.random()
if (r>0.5)
{document.write("<a href='http://www.w3schools.com'>Learn Web Development!</a>")

}else
{document.write("<a href='http://www.refsnesdata.no'>Visit Refsnes Data!</a>")
}</script>
</body></html>

Activity (30)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Hanse69 liked this
Hanse69 liked this
akhyarchuckz liked this
ALi liked this
deepkulehri liked this
VINAY liked this
akkiaarti liked this
Rajendran liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->