JavaScript How To ...
The HTML <script> tag is used to insert a JavaScript into an HTML
page.
Examples
Write text
How to write text on a page.
Write text with formatting
How to format the text on your page with HTML tags.
How to Put a JavaScript Into an HTML Page
<html>
<body>
<script type="text/javascript">
document.write("Hello World!")
</script>
</body>
</html>
|
The code above will produce this output on an HTML page:
Example Explained
To insert a JavaScript into an HTML page, we use the <script> tag (also
use the type
attribute to define the scripting language).
So, the <script type="text/javascript"> and </script> tells where the
JavaScript starts and ends:
<html>
<body>
<script type="text/javascript">
...
</script>
</body>
</html>
|
The word document.write is a standard JavaScript command for writing output to a page.
By entering the document.write command between the <script type="text/javascript">
and </script> tags, the browser will recognize it as a JavaScript command and
execute the code line. In this case the browser will write Hello World! to the page:
<html>
<body>
<script type="text/javascript">
document.write("Hello World!")
</script>
</body>
</html>
|
Note: If we had not entered the <script> tag, the browser would have
treated the document.write("Hello World!") command as pure text, and just write the entire line on the page.
Ending Statements With a Semicolon?
With traditional programming languages, like C++ and Java, each code statement
has to end with a semicolon.
Many programmers continue this habit when writing JavaScript, but in general, semicolons are
optional! However, semicolons are required if you want to put more than one statement on a single line.
How to Handle Older Browsers
Browsers that do not support JavaScript will display the script as page
content. To prevent them from doing this, we may use the HTML comment tag:
<script type="text/javascript">
<!--
document.write("Hello World!")
//-->
</script>
|
The two forward slashes at the end of comment line (//) are a JavaScript comment symbol.
This prevents the JavaScript compiler from compiling the line.
What do you want your Web site to do?

What do you want your Web site to do? Ektron CMS400.NET lets you do everything you need to do on the Web and do everything you want to do.
Ektron CMS400.NET gives you all the features you would expect from an
enterprise CMS, but also high-demand functionality like real-time Web
site analytics, community building, blogging, personalization, and
online calendars. Ektron CMS400.NET bridges your Web site gaps.
Use Ektron CMS400.NET for:
- Content & Document Management - Author/edit content, manage navigation, menus, audit trails, workflow, approvals
- Personalzation & Portal Support - Allow visitors to create their own view of your web page
- 508 & W3C Compliance Checker - Ensure compliance with scheduled or on-demand compliance reports
- Memberships - Build online communties with blogs and forums, enable email web alerts, build polls and surveys
- Web Site Analytics - track visitors, report on most requested pages, see where they came from and where they are going
- HTML Form Engine - Create a two-way dialog with visitors using our wizard-like HTML form-building engine with validation and database support
- Multilingual Support - Integrated translation tools help you reach multiple audiences by speaking their language
- Online Calendars - Build and manage Web-based calendars and enable users to customize a view based on what’s important to them
See why there are 15,000+ Ektron integrations worldwide.
Click here to learn more, then request a live online demo or download a FREE TRIAL
 |
|
Get Your Diploma!
W3Schools' Online Certification Program is the perfect solution for busy
professionals who need to balance work, family, and career building.
The HTML Certificate is for developers who want to document their knowledge of
HTML, XHTML, and CSS.
The ASP Certificate is for developers who want to document their knowledge of
ASP, SQL, and ADO.
|
|