Welcome to MSDN Blogs Sign in | Join | Help

IE Tips and Tricks - Part 1

It has occurred to me that I haven’t written much about client-side development and all that fun web browsery stuff.  Before I get branded a server only guy, I’ve decided to write an n part series (where n is the number of articles I can write before getting bored of the subject) about my favorite HTML/CSS/Script tips and tricks.

 

The first is none other than DHTML expressions.  DHTML expressions were a new feature in Internet Explorer 5 (back when the IE team was still attempting to innovate), however are still not used very often because of bugginess and performance issues.  I’ve also seen several IE bugs that cause the IE window to crash if an expression exists against an object that’s since been removed from the DOM.  I maintain that DHTML expressions (also called CSS expressions and “dynamic properties”) are quite helpful if used in very simple solutions, where the expression is something that can be resolved quickly as the IE DOM changes.

 

Expressions can be declared inline using a style attribute, within a CSS selector, or using script.  I prefer the latter two since it keeps things simple.  One of my favorite uses of expressions is to show and hide various UI depending on the state of a check box, radio button, or dropdown value.  It allows UI to be hidden if certain options are not selected, or allows for an easy implementation of a “Show Advanced” checkbox.

 

In my example, I’m creating a simple time sheet that shows hours worked per pay period, and allows the user to show various classifications of work (Actual hours worked, Planned hours, and Overtime hours.)  None of this uses script and it’s easy to see how it works, and doesn’t require logic complicated enough to warrant the use of a debugger (good luck debugging problems caused by expressions.)

 

Here’s my web page for you to copy into notepad and save locally:

 

<style>

   BODY {font-family: Arial; font-size: 11px;}

   TABLE {width: 75%; border: 1px solid grey;}

   TH {background: #BBBBBB;}

   .Total TD {text-align: right; border-top: 2px solid #999999;}

   .Planned {display: expression(cbPlanned.checked ? '' : 'none'); background: #BBBBFF; text-align: right;}

   .Actual {display: expression(cbActual.checked ? '' : 'none'); background: #BBFFBB; text-align: right;}

   .Overtime {display: expression(cbOvertime.checked ? '' : 'none'); background: #FFBBBB; text-align: right;}

</style>

 

<input type="checkbox" id="cbPlanned"><label for="cbPlanned" style="background: #BBBBFF;">Show Planned</label>

<input type="checkbox" id="cbActual"><label for="cbActual" style="background: #BBFFBB;">Show Actual</label>

<input type="checkbox" id="cbOvertime"><label for="cbOvertime" style="background: #FFBBBB;">Show Overtime</label>

 

<table cellpadding="0" cellspacing="0" rules="cols">

       <tr><th>Period</th><th>Date</th><th>Work</th></tr>

 

       <tr class="Total"><td>1</td><td>1/1 - 1/7</td><td>40h</td></tr>

       <tr class="Planned"><td colspan="2">&nbsp;</td><td>40h</td></tr>

       <tr class="Actual"><td>&nbsp;</td><td>&nbsp;</td><td>40h</td></tr>

       <tr class="Overtime"><td>&nbsp;</td><td>&nbsp;</td><td>0h</td></tr>

      

       <tr class="Total"><td>2</td><td>1/8 - 1/14</td><td>48h</td></tr>

       <tr class="Planned"><td colspan="2">&nbsp;</td><td>40h</td></tr>

       <tr class="Actual"><td>&nbsp;</td><td>&nbsp;</td><td>40h</td></tr>

       <tr class="Overtime"><td>&nbsp;</td><td>&nbsp;</td><td>8h</td></tr>

 

       <tr class="Total"><td>3</td><td>1/15 - 1/21</td><td>32h</td></tr>

       <tr class="Planned"><td colspan="2">&nbsp;</td><td>40h</td></tr>

       <tr class="Actual"><td>&nbsp;</td><td>&nbsp;</td><td>32h</td></tr>

       <tr class="Overtime"><td>&nbsp;</td><td>&nbsp;</td><td>0h</td></tr>

</table>

 

As you can see, most of the logic is within the <style> block.  Each planned work row has a class of “Planned”.  In the CSS definition for the Planned class, the “display” property has an expression of whether or not the cbPlanned checkbox is checked.  When the checkbox is un-checked, the display property of the CSS class becomes ‘none’.

 

Click Here to load this file in your web browser.

 

That’s it!

 

Mike – Web Dev Guy

Published Tuesday, June 27, 2006 11:03 PM by mikechr
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: IE Tips and Tricks - Part 1

Wednesday, June 28, 2006 2:52 AM by Marc Brooks
Does the term cross-browser support mean ANYTHING to you?

# re: IE Tips and Tricks - Part 1

Wednesday, June 28, 2006 3:14 AM by mikechr

Good question..

I got out of web development ages ago for this very reason; differences in scripting, HTML rendering, and various standards support made it completely impossible to support multiple browsers perfectly.  To do anything slightly complicated, you'd have to detect which browser the user had and render a different version of the page.

That's why I do web applications now - for the most part, our applications (such as Project Web Access) are built to run on IE, or at the most provide a scaled down version for other browsers.

Keep in mind IE is a platform and is designed to build web applications on.  Having IE is simply a prerequisit for running these applications, just like Windows is a prerequisit for running Windows applications.  Part of the reason that Netscape mostly died off around the IE4/NS4 time is that Netscape saw itself as a web browser and IE saw itself as a platform for web based applications.  Within corporate Intranets, IE is used as the foundation for developing in-house solutions for tasks like submitting a timesheet, setting up direct deposit, and accessing company information.  Building solutions on this platform is a subject my blog heavily focuses on.

I will agree with you that supporting multiple browsers is essential for Internet web sites such as MSN and Google, but there's plenty of blogs on web design.

Also note the title of the posting is "IE Tips and Tricks" and not "Tips for writing web pages that run on every browser ever made."

# re: IE Tips and Tricks - Part 1

Wednesday, June 28, 2006 3:58 AM by Vinod Inamdar
Yeah. Marc should have looked at the tagline.

# re: IE Tips and Tricks - Part 1

Wednesday, June 28, 2006 6:58 AM by Aaron Jensen
That was a very Web 1.0 rebuttal, Mike :)  Regardless, it seems most of the cross-browser issues stem from IE trying to "innovate" while ignoring actual CSS "standards"... but neat IE trick anyways.

# re: IE Tips and Tricks - Part 1

Friday, August 11, 2006 11:59 AM by argatxa
mmmm.....   example page...
"'cbPlanned' is undefined"

tut tut tut...

I prefer the old Javascript DOM style.

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker