javascript - Common applications

I consider javascript the language of last resort. The browser compatibility and security issues associated with it can make it the most complex part of a page. For this reason, I strive to deliver pages to the browser ready for display. This isn’t always possible.

javascript is a vital part of web development, and I use it alot, but carefully. The following list describes some of the most common uses of javascript:

  • Alert boxes (usually just debugging)
  • Confirm boxes - great for ‘Are you sure … ‘ processing
  • Detection of form inputs changed to ensure user doesn’t lose changes
  • Changing state of buttons and inputs to disabled/readonly and back again
  • Changing status displays, like colors or text on the page
  • Opening new windows (, often used for help and … Easter Eggs :)
  • Timers (see post about Ladybug)
  • Google (and other) Map APIs - these are cool
  • Hiding content / menuing, using style.display="block/inline/none”
  • Client-side validation and assisting the user in correcting errors, must revalidate on on server-side
  • Page level validation - Ensuring that inputs are not only valid, but valid with respect to each other - for example if the status is ‘extended absence’, a return date must be specified. As mentioned about, server-side validation must also be performed.
  • RIAs (Rich Internet Applications) - Sophisticated interfaces. These are usually based off javascript libraries & kits like dojo. Fundamental javascript skills are vital to work with the toolkits.
  • Control of players - like Windows Media player and Flash
  • Browser-specific page adjustments that can’t be done on the server-side
  • Used to add things like Google analytics, support external data collection systems, also Google ads
  • Choosing different .CSS files - often used to assist visually impaired site visitors with text size or color choices
  • AJAX
  • Input interaction - For example, if one input is chosen, another may be presented or set to a specific value

Google Map - Flying Ladybug (US)

The code snippet below allows you to add a ladybug (or any other image), to fly over a map. The coordinate boundaries are for the United States (min_lon, min_lat, max_lon, max_lat), but you can change them to suit your needs.

After a random number of seconds, the ladybug lands on the map. When the site visitor moves the mouse over the ladybug, she will fly to a different, random point on the map. This continues forever. The site visitor will tire of this long before the ladybug does. :)

This piece of code was named cartesian/optimize.js and included into page with a script tag. This allows you to quickly remove the code prior to deployment.

Recommended application … none. This is strictly for fun.

var bugIcon = new GIcon();
        bugIcon.iconSize=new GSize(32,32)
        bugIcon.shadowSize=new GSize(0,0)
        bugIcon.iconAnchor=new GPoint(16,32)
        bugIcon.infoWindowAnchor=new GPoint(16,0)
var bugFlag = new GIcon(bugIcon,'cartesian/bug.gif',null,null)


var bug=0

function makeBug()
bug=new GMarker(new GLatLng(lat, lon),bugFlag)
GEvent.addListener(bug, "mouseover", flyBug)

function flyBug()
delete bug
bug=new GMarker(new GLatLng(lat, lon),bugFlag)
GEvent.addListener(bug, "mouseover", flyBug)

window.setTimeout("makeBug()", 25000*Math.random());

Thank You Malwarebytes

I don’t often “surf the ‘net", visiting unfamiliar sites. Most of my Internet access is in search of LAMP/RIA technical resources and answers, as well as contributing my own through this blog and on the appropriate sites.

Recently, I was checking a search engine for entries related to a site and I clicked on htxx:– (the xxs and -s are there to prevent it from being a real URL). It infected my computer with a nasty virus. Key filenames: brastk.exe, beep.sys, delself.bat, bnokdcme.exe, as well as others and registry corruption. It prevented execution of autoruns.exe, although renaming autoruns to a different name allowed it to run. It put a little red X image in the taskbar, prompting me to click to download ‘Antivirus2009′.

I won’t describe how the files were identified, or any of the other resolution tactics - to avoid assisting the authors. However, if it shows up on your computer, the posted link solved the problem on this machine very nicely.

Sincere thanks to the author and I will purchase a copy of the product.

Have the Server Watch Your Account

This crontab entry will email you a report of all the files modified within the past 24 hours.

find $HOME -mtime 0

Search for files in your home directory which have been modified in the last twenty-four hours. This command works this way because the time since each file was last modified is divided by 24 hours and any remainder is discarded. That means that to match -mtime 0, a file will have to have a modification in the past which is less than 24 hours ago.

Describes how to set up a cron job, so the command will execute periodically and email you the results.


5 0 * * * find $HOME/public_html -mtime 0

This simple command will let you know when files have been added to your server. You may want to disallow some files or directories.

Cool Hover Effect

The link above provides a nice hover effect, done with CSS and a tiny bit of javascript.

The approach is to use two divs. The outer or container div has a background image assigned through CSS. The inner div contains the text, and is hidden (display:none) on page load. The inner div uses a white background, with opacity to mute the background image and make it easier to view the image.

On hover, the inner div is changed to display:block.

Both divs have an id and class. The outer div id is required to assign the background image, the class is used to set float:left, and any other common attributes. The inner div id is used to identify it in the javascript, so the display attribute can be controlled, and the class is used to describe and position the text and opacity.

The code was written to run within a loop, hence the 1 on the ids.