Scott Hanselman

Making Negative Numbers turn Red using CSS and Javascript

May 01, 2006 Comment on this post [9] Posted in ASP.NET | Javascript
Sponsored By

A common thing one wants to do in a table of financial figures is to turn negative numbers red. Given that folks would rather use CSS than <font>, there's some conflicting thinking around the right way to do it.

Some propose adding "negative" a css class like:

<TD CLASS="financial negative">-190</TD>

but others find that distasteful and say:

  • number is a data type.
  • currency is both a presentational instruction and a sub-type of the number data type.
  • negative is neither type nor presentational — it’s dependent on the data value, not the type or the author’s formatting preference. It doesn’t belong there. [Xaprb]

and go on to provide a clever CSS-only technique that works everywhere but IE6 (demo here).

In the specific situation I've got, I'd like to make the change without changing any server-side code (which precludes adding a "negative" css class) and I need it to work everywhere (which nixes clever css).

So, here's my not-so-clever Javascript solution (Warning, I'm not a Javascript guy so give Phil a few minutes and he'll no doubt include color commentary).

<html>
<head>
    <style type="text/css">
     td.negative { color : red; }
    </style>
    <script language="JavaScript" type="text/javascript">
    <!--
    function MakeNegative() {
        TDs = document.getElementsByTagName('td');
        for (var i=0; i<TDs.length; i++) {
                var temp = TDs[i];
                if (temp.firstChild.nodeValue.indexOf('-') == 0) temp.className = "negative";
            }
    }
    //-->
    </script>
</head>
<body>
 <table id="mytable">
  <caption>Some Financial Stuff</caption>
  <thead>
    <tr><th scope="col">Date</th><th scope="col">Money is good</th></tr>
  </thead>
  <tbody>
  <tr><td>2006-05-01</td><td>19.95</td></tr>
  <tr><td>2006-05-02</td><td>-54.54</td></tr>
  <tr><td>2006-05-03</td><td>34.45</td></tr>
  <tr><td>2006-05-04</td><td>88.00</td></tr>
  <tr><td>2006-05-05</td><td>22.43</td></tr>
  </tbody>
 </table>
    <script language="JavaScript" type="text/javascript">
  <!--
   MakeNegative();
  //-->
    </script>
</body>

May not be Web 2.0, and it likely doesn't please the standards wonks, but it works.

UPDATE: Similar attempt seen here.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

ASP.NET MVP Hacks

April 30, 2006 Comment on this post [5] Posted in ASP.NET | TechEd | ViewState | HttpHandler | HttpModule
Sponsored By

0764597663.01._SCLZZZZZZZ_V52483501_David Yack got a bunch of folks together and assembled ASP.NET 2.0 MVP Hacks from Wrox. Take a look at the picture on the right, totally looks like we're all in the same room with our twelve-sided dice, no? ;)

Seriously though, it's a good collection of "messing with ASP" hacks. I did the sections on HttpHandlers/HttpModules and the ViewState hacks. Some of the content came from my blog. I also pulled in content, with permission and attribution from a number of other smart ASP.NET blogs. Most hacks work on both ASP.NET 1.x and 2.0 as well.

A book with a Brady Bunch cover full of nerds, yes.

A book with a lot of slick hacks, totally.

Big ups and congrats to David for pulling it all together, he's really been working hard on this book and I'm happy to have been involved along with the other (very seasoned) authors David Yack, Joe Mayo, Fredrik Normén, Dan Wahlin, J. Ambrose Little, and Jonathan Goodyear.

ASP.NET 2.0 MVP HacksProfessional ASP.NET 2.0
Total List Price: $89.98
Buy Together Today: $57.88

If you're looking to get this and Pro ASP.NET 2.0, the total price is only $57.88 on Amazon right now as a bundle. To be clear, the content in these two books doesn't overlap. The Hacks book is focused on specific and finite tips, tricks, and undocumented features and manipulations of ASP.NET Features, while the Pro ASP.NET book starts with fundamentals and builds feature by feature to advanced topics advanced to Professional ASP.NET 2.0 developers.

 

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Replacing Explorer.exe - The Return of Norton Commander with xplorer2 and FAR

April 29, 2006 Comment on this post [19] Posted in Reviews | PowerShell | Tools
Sponsored By

Far1"The Norton Commander is the most useful DOS program ever written" says the Commander Homepage, a site dedicated to Norton Commander. And true it is. NC was flippin' fabulous. I used the crap out of that program. You think I'm fast now, back in day™ I was fast as lightning on a stac'ered 386sx. Those were the days.

Misha Bergal emailed me recently reminding me of FAR, a text-mode Norton Commander clone with Windows long filename support. Wow, takes me back.

Sure, PowerShell is a better shell. The best ever, even, there's no question of that (Seriously, get on board, the PowerShell is poised to take over the planet, but I digress...) but if you really want to stop dragging files around in Explorer and start doing some serious damage, take a look at these potential additions to your tools list.

The first is FAR and the real story is it's plugin support. Some of my favorite features? Start it up and press Ctrl-UpArrow for a while, then Ctrl-DownArrow. Now try Alt-F9. Try Ctrl-W. It'll take a while to get used to, but wow, you can fly once you've taken off.

Xplorer1

My other favorite Explorer Replacement is xplorer2 from Zabkat. There's so much goodness in xplorer2 I will have to blog about it separately. It's got the same familiar Norton Command dual-pane view with the quick switching with "Tab" feature. It has integrated file preview and all the things you'd expect, but also throws in a great folder synchronizer, an amazing "mass file rename" token language for those large tricking bulk renames, rule-based file section, a macro language and it starts up faster than a new explorer window.

Both of these great tools are bound to hotkeys on my systems and make my life easier.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Mourning Monad - This whole Monad, MSH, Microsoft Command Shell, PowerShell thing is tearing me up inside

April 27, 2006 Comment on this post [7] Posted in PowerShell
Sponsored By

PowerShellThis whole name change thing is tearing me up.

Note the screenshot at the right while searching Microsoft.com for "Powershell." Even Microsoft.com isn't comfortable with the name change.

If you're having trouble getting the downloads as no search engine, even Google, is willing to give up the goods when searching for "PowerShell" or "John Smith" or other fantastically descriptive names, here they are:

I did set up a SlickRun shortcut to PowerShell as well as a msh.bat file in my Windows Folder so I could "moosh" my way to denial.

Here's what I'm going through as Monad becomes Powershell. Or, is it PowerShell? PowerShell! POWerSHELL!

1 - Denial - "this can't be happening to me", looking for former shortcuts or files in familiar places. Setting the table for Monad or acting as if he is still living here. Not crying. Not accepting or even acknowledging the loss.

2 - Anger - "why me?", feelings of wanting to fight back or get even with Monad, for death, anger at the deceased, blaming them for leaving.

3 - Bargaining - bargaining often takes place before the loss. Attempting to make deals with the shell who is leaving, or attempting to make deals with God to stop or change the loss. Begging, wishing, praying for them to come back.

4 - Depression-overwhelming feelings of hopelessness, frustration, bitterness, self pity, mourning loss of Monad as well as the hopes, dreams and plans for the future. Feeling lack of control, feeling numb.

5 - Acceptance - there is a difference between resignation and acceptance. You have to accept the loss of Monad, not just try to bear it quietly. Realization that it takes two to rename a command shell. Realization that Monad is gone (as in death) that it is not Monad's fault, they didn't leave you on purpose. Finding the good that can come out of the pain of loss, finding comfort and healing. Our goals turn toward personal growth. Stay with fond memories of Monad.

Sigh. Come here, PowerShell, gimme an uncomfortable heterosexual hug.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Hanselminutes Podcast 15

April 27, 2006 Comment on this post [5] Posted in Podcast | ASP.NET | XML | Tools
Sponsored By

HanselminutesMy fifteenth Podcast is up. This episode is about replacing Start|Run.

We're listed in the iTunes Podcast Directory, so I encourage you to subscribe with a single click (two in Firefox) with the button below. For those of you on slower connections there are lo-fi and torrent-based versions as well.

Subscribe to my Podcast in iTunes

Our sponsors are PeterBlum and the .NET Dev Journal.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

  • Each show will include a number of links, and all those links will be posted along with the show on the site. There were a number of sites mentioned in this episode, some planned, some not.
  • The basic MP3 feed is here, and the iPod friendly one is here. There's a number of other ways you can get it (streaming, straight download, etc) that are all up on the site just below the fold. I use iTunes, myself, to listen to most podcasts, but I also use FeedDemon and it's built in support.
  • Note that for now, because of bandwidth constraints, the feeds always have just the current show. If you want to get an old show (and because many Podcasting Clients aren't smart enough to not download the file more than once) you can always find them at http://www.hanselminutes.com.
  • I have, and will, also include the enclosures to this feed you're reading, so if you're already subscribed to ComputerZen and you're not interested in cluttering your life with another feed, you have the choice to get the 'cast as well.
  • If there's a topic you'd like to hear, perhaps one that is better spoken than presented on a blog, or a great tool you can't live without, contact me and I'll get it in the queue!

Enjoy. Who knows what'll happen in the next show?

Now playing: Newsboys - He Reigns

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.