Equal Height for Division (div) Elements using JavaScript

On problem I run into on a regular basis when developing web sites is that I have 2 or 3 divisions on a page that need to be the same height. This is no problem to accomplish with style sheets, just set the height property to whatever you need: height: 100px;. This becomes more difficult with dynamic text or across multiple pages. This is where JavaScript comes in handy:

function adjustHeight(elem1, elem2)
{
  var e1 = document.getElementById(elem1);
  var e2 = document.getElementById(elem2);
  if (e1 && e2)
  {
    var h1 = e1.offsetHeight;
    var h2 = e2.offsetHeight;
    if(Math.max(h1, h2) == h1)
    {
      e2.style.height = h1 + "px";
    }
    else
    {
      e1.style.height = h2 + "px";
    }
  }
}

The adjustHeight(elem1, elem2) function above takes in the id of two elements, checks to see if they actually exist, determines which element has a greater height, and sets the height of the smaller element. The offsetHeight attribute of an element is read-only (meaning we cannot assign a value to it) and returns the height of the element (including scrolling) as an integer value in pixels. We actually set the height of the element through manipulation of the elements style: e1.style.height. Theheight property must have a unit of measurement, and since offsetHeight returns pixels, we assign pixels (“px”) to the property: e2.style.height = h1 + "px";

To use this function in you code, place this script within the <head> tag of you page, being sure to identify the script as JavaScript: <script type="text/javascript">. You can then call the function using: adjustHeight("left","right"); where left and right are the elements you want equal size.

One further note: make sure this function is called after the elements have been loaded on the page. Otherwise, you will not see anything happen. One way to ensure this is putting a <script> block immediately after the elements you want resized. Another way is to attach an event to the page load that triggers the function: <body onload="adjustHeight("left","right");"> (there are better ways to attach events, this is just the simplest to write here)

Book Review: "Bruce Lee: Artist of Life"

Rating: 4 out of 5

Bruce Lee: Artist of Life is a collection of letters, journals, and drafts crafted by Bruce Lee throughout his life. John Little organizes the essays in this book into eight categories: Gung Fu, Philosophy, Psychology, Poetry, Jeet Kune Do - The Liberation, Acting, Self-Knowledge, and Letters. Throughout the book, Bruce Lee stresses one fact above all others: I cannot teach you; only help you to explore yourself. Nothing More. Through the writings, we learn that Bruce Lee valued self-knowledge and self-actualization first and foremost. Even in his martial arts, Jeet Kune Do (the way of the intercepting fist), focuses on using your skills to break through the mental blocks and demons inside oneself to gain a better understanding of who one is.

I enjoyed reading this book. I have been a fan of Bruce Lee even since my dad showed me Enter the Dragon as a little kid. This peek into who Bruce Lee was, his mental processes and plans, adds a warmer glow to the martial arts expert. The way he lived his life and the inspiration he gave to others is a model that should be more prevalent today.

But [to] those who kept saying
"It can't be done,"
Never are the victories
Or the honors won.
But, rather,
By the believing, doing kind,
While the doubters
Watched from far behind.

-- excerpt from Which Are You?, a poem by Bruce Lee, page 255

Book Review: Michael Crichton's "Electronic Life"

Rating: 3 out of 5

Michael Crichton's Electronic Life is a non-fiction piece of work that aimed to educate people who were looking into buying a computer for the first time in 1983. Crichton talks about the practical matters when it comes to deciding what computer to buy in his discussion of everything from A (Afraid of Computers) to Z (Zenith: The Final Days).

An interesting piece of knowledge I picked up while reading this book is that the 1973 movie, Westworld, that Michael Crichton wrote and directed, was the first feature film to digitally process film. They obtained a sort of blocky, animated effect as the point-of-view for a robot.

I have taken a course about the history of computing, so I am familiar with all the technical advances that have happened over the years. But the books I had to read did not give a good first-hand view of computing. That is what this book did. It presented a first-hand view of the state of computing in 1983. Reading the book in 2007, there were a few pretty funny exerts:

Buying a Computer: Specifically, think carefully before you buy a machine that can't run under CP/M. -- Page 25

Memory: The earliest machines had only 4K; most machines are now sold with at least 16K, and many users feel unhappy without at least 64K. -- Page 93

Monitor: Color monitors are generally unsatisfactory for text displays. If you want to view both color graphics and text, you probably need two monitors. -- Page 99

Notebook: Keep a notebook for your machine. -- Page 101

Operating System: Some operating systems, such as CP/M, are referred to as "popular," as if the operating system were a thing to be embraced in its own right. -- Page 101

Even though Michael Crichton wrote Electronic Life almost 25 years ago, some points he makes do still apply to buying a machine today:

Debugging: Programs never work the first time. -- Page 50

Documentation: Many otherwise excellent programs have astoundingly bad instructions. -- Page 59

Parents: You've just bought a home computer, but before you've even figured out how to turn the damn thing on, your seven-year-old daughter starts banging away at it, making it do all kinds of tricks. -- Pages 104-105

Computer Widow: The little machines are incredibly compelling, and one can work them long into the night. [...] She's back in two hours, stamping her foot, insisting you come to bed. [...] She's a computer widow, and you have a problem. -- Pages 133-134

The first computer I remember growing up with was a Wang Labs computer running a 80386 processor and Windows 3.11. I can remember upgrading the memory, adding an external CD-ROM drive, and connecting to the "Internet" through a 14.4Kbps modem. And, throughout my life, I have worked on a few monochromatic monitors.

Electronic Life was a good nostalgic book to read. If you are interested in the state of computers in 1983, I suggest you read this book.

Book Review: Ian Fleming's "On Her Majesty's Secret Service"

Rating: 4 out of 5

The 11th book in Ian Fleming's James Bond series begins with Bond drafting his third attempt on a letter of resignation. For the past year in Bond's life, he has been playing detective trying to track down Blofeld, the former number 2 in the SMERSH organization (before SMERSH was disseminated after operation Thunderball). After going no were with the case and repeated attempts to return to his normal double-oh work, Bond figures his only way out of his monotonous nightmare is to resign. On his way back to headquarters, Bond makes a stop at Casino Royale and falls in love with a beautiful girl, Tracy, who happens to be the daughter of the head of the largest European crime syndicate, Marc-Ange Draco. Marc-Ange, after finding out how Bond saved his daughter's life at the hotel casino, does a favor for Bond by finding out Blofeld is alive and living in a remote area of Switzerland.

With this new information, Bond's faith in his service is renewed. He must go undercover as an officer of the College of Arms (a heraldic authority in Europe) in order to gain access to Blofeld's secret hideaway. Bond barely escapes with his life thanks, in part, to the help of Tracy (to whom which he eventually becomes engaged). After learning that Blofeld is involved with Biological Warfare, Bond must meet with Marc-Ange to come up with a plan to stop Blofeld once and for all...

Overall, On Her Majesty's Secret Service was a great book with a few interesting twists that are not present in the other books of the series. A good rebound from the The Spy Who Loved Me interlude.

Movie Review: "A Scanner Darkly"

Rating: 3.5 out of 5

From the people who brought you Waking Life, from which all I remember was thinking the artists were forced to draw with their toes during an earthquake. Well, it turns out, I actually liked the story and animation within A Scanner Darkly, and I might go back and give Waking Life another chance. A Scanner Darkly is set in the not to distant future (I believe it is "7 years from now") where a mysterious new drug, Substance D (not to be confused with the obscure metal band from California), claims most people addicts. Keanu Reeves plays an undercover agent who has fried his brain on the very drug he is trying to track down to source of. The most likely candidate for the source of Substance D, is actually a help group called "New Path" who help people recover from the drug, and incidentally is the only location in America that is not covered by security camera 24/7. The police agency, of which Keanu's character is a part of, wear "scramble suits" to keep their identity hidden from everyone. The medics at the police agency begin to discover Keanu's character is showing signs of Substance D addiction (a good album by the way - Substance D: Addictions), which may force him to have to enter New Plan...

I thought the movie was pretty entertaining, as well as the making of documentary in the bonus features of the DVD. The entire movie was first shot in live-action, then a team of animators spent about 18 months drawing the movie frame-by-frame. I had just assumed they applied some graphic algorithm on top of the raw footage, but instead, they used a technique called Rotoscoping. I recommend this movie to people who enjoy thinking about alternate realities and what the future may hold.