Write
a basic script
You'll begin by writing a simple script that outputs a text string.
There are two methods to display text:
document.write("text"); or
document.witeln("text");
Think of document as an object and write or writeln as a method, or
action, applied to the object. You'll typically use the write method
for outputting. The writeln method is applicable when using the <pre>
tag, which causes the browser to insert a carriage return or new line
after applying the method. Note that the command ends with a semi-colon.
You may optionally insert HTML code within the output string as follows:
document.write("<h3>Text</h3>");
or
document.write('<td class="calendar">');
Notice the use of single and double quotes. JavaScript commands are
also typically case sensitive.
Download the HTML page.
Open npntxt.htm and edit it as follows:
Delete the following:
Today is 6/27/2003<br>
Only 181 days until Christmas
Insert:
<script language="JavaScript">
<!-- Hide from old browsers
document.write("Today is 11/3/2003<br>");
document.write("Only 52 days until Christmas");
Save the file and view it in the browser.