Introduce DataBase,Asp.net,JavaScript,Xml,Html,Css,Sql,Php,ASP.NET Controls,AJAX,Tools,HTML,CSS,JavaScript,Open Source Project,WPF,.Net Framework,Linq
Top Recommended Hosting

Javascript: Adding the Script to a Web Page

by the3factory 3/25/2008 7:00:00 AM

You should now have a complete script that calculates a result and displays it. Your listing should match Listing 2.1.

Listing 2.1. The Complete Date and Time Script

<script language="JavaScript" type="text/javascript">
            now = new Date();
            localtime = now.toString();
            utctime = now.toGMTString();
            document.write("<b>Local time:</b> " + localtime + "<BR>");
            document.write("<b>UTC time:</b> " + utctime);
            </script>

To use your script, you'll need to add it to an HTML document. In its most basic form, the HTML document should include opening and closing <html> tags, <head> tags, and <body> tags.

If you add these tags to the document containing your script along with a descriptive heading, you should end up with something like Listing 2.2.

Listing 2.2. The Date and Time Script in an HTML Document

<html>
            <head><title>Displaying Times and Dates</title></head>
            <body>
            <h1>Current Date and Time</h1>
            <p>
            <script language="JavaScript" type="text/javascript">
            now = new Date();
            localtime = now.toString();
            utctime = now.toGMTString();
            document.write("<b>Local time:</b> " + localtime + "<BR>");
            document.write("<b>UTC time:</b> " + utctime);
            </script>
            </p>
            </body>
            </html>

Now that you have a complete HTML document, save it with the .htm or .html extension.

Related posts

Sign up for PayPal and start accepting credit card payments instantly.


Powered by BlogEngine.NET 1.2.0.0