WebDeveloper.com �: Where Web Developers and Designers Learn How to Build Web Sites, Program in Java and JavaScript, and More!   
Web Developer Resource Directory WebDev Jobs
Animated GIFs
CSS Properties
HTML 4.01 Tags
Site Management
WD Forums

    Web Video
    Expression Web



    Forum, Blog, Wiki & CMS

 Site Management
    Domain Names
    Search Engines
    Website Reviews

 Web Development
  Business Issues

    Business Matters

    The Coffee Lounge
    Computer Issues

JavaScript for the Holidays

by Heidi Brumbaugh

These JavaScript tidbits, culled from questions in my mailbag, make excellent stocking stuffers for those hard-to-shop-for Webmasters on your list.

Fa La La La DrawPoint

I've had several readers ask me lately about using JavaScript to draw on the page. A little surfing saved me a lot of work on this one: Bill Dortch of ColorCenter fame has written a set of drawing functions for Special Edition: Using JavaScript, from Que. You can pull these functions from his DoodlePad site . Okay, so perhaps ColorCenter isn't famous, but it is linked to from just about every JavaScript index I've seen and is worth a look by any aspiring JavaScript programmer.

A Few of my Favorite Strings

String manipulation is another topic I continue to get questions on. Programming languages are great for repetive tasks, especially when you want to make a small change to a general pattern each time you perform the task. Jim Thompson sent this question about using JavaScript to generate filenames. I've integrated the answer to this question into a for loop, which is a programming construct that lets you perform an operation a specific number of times.

I would like to write HTML code that will load sequential pages of a document. I think javascript is the way to go. The HTML pages are named 1page.htm, 2page.htm, 3page.htm and so on up to 50 something. I would like to just add 1 to the "1page.htm" and get "2page.htm" or click PREV and minus one from "2page.htm" and get "1page.htm" but I do not know how to handle number and strings in JavaScript. I have done this many times in BASIC or PASCAL but never in HTML. Help if you can. THANKS!

The trick here will be combining the number you want with the text ("page.htm"). JavaScript has loose variable typing, which means (among other things) that you can concatenate integers and strings without the pesky type changing you might need in other languages. Here's a loop to generate a list of filenames. You could use this to generate a menu "on the fly".

Here's the sample code

 for (i=0;i<=10;i++) { myHtmlFile = i + "file.htm" document.write(myHtmlFile) document.write("
") }

[Jump to Part 2]

Web Developer® Site Feedback
Web Developer®
Copyright © 1999-2001 internet.com Corp.
All rights reserved.

HTML5 Development Center

Recent Articles