p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Web Programming > JavaScript > Javascript How-To
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 11th, 2004, 07:15 PM
Authorized User
Points: 143, Level: 2
Points: 143, Level: 2 Points: 143, Level: 2 Points: 143, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to pigtail Send a message via Yahoo to pigtail
Default Change background color using CSS

The code I downloaded below was to change a 'td' field to right align if it was a currency. I tried to change the code so that it will display red when a negative number is displayed. It doesn't work. Do you know why?

    <style type="text/css">
    <!--
    td.negative { background-color : red; }
    -->
    </style>

    <script language="JavaScript" type="text/javascript">
    <!--
    function PhoneHome() {

        var shoePhone = document.getElementById('shoePhone');
        shoePhone.src = "datafeed.js";
    }

    function ReceiveData(response) {

        var table = document.getElementById('results');
        var oldTbody = table.getElementsByTagName('tbody')[0];
        var newTbody = document.createElement('tbody');
        table.replaceChild(newTbody, oldTbody);
        for (var i=0, istop=response.length; i<istop; i++) {
            var tempRow = document.createElement('tr');
            for (var j=0, jstop=response[i].length; j<jstop; j++) {
                var tempCell = document.createElement('td');
                var tempText = document.createTextNode(response[i][j]);
                tempCell.appendChild(tempText);
                tempRow.appendChild(tempCell);
                if (tempText.nodeValue.indexOf('-') == 0) tempCell.setAttribute("class", "negative");
            }
            newTbody.appendChild(tempRow);
        }
    }
    //-->
    </script>
</head>




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old July 20th, 2004, 09:04 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I use

tempCell.innerHTML = "" + response[i][j] + "";



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old July 20th, 2004, 01:08 PM
Friend of Wrox
Points: 2,801, Level: 22
Points: 2,801, Level: 22 Points: 2,801, Level: 22 Points: 2,801, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Since this topic has come up....

innerHTML is IE only, and the attribute is depreciated.

Personally, I don't care for the fancy setAttribute() and createElement() functions, why not just print it out directly? Aren't those IE only, anyway? Not sure.... :-)

HTH,

Snib

<><
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old July 20th, 2004, 09:38 PM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Snib, it is for Flickering.

I encountered this problem same as "pigtail". I don't have time to find better way to solve it. That is why I cut it short. Any better suggestion?

Simon



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old July 21st, 2004, 04:23 AM
Friend of Wrox
Points: 1,374, Level: 14
Points: 1,374, Level: 14 Points: 1,374, Level: 14 Points: 1,374, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 685
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Simon,

The original code

Code:
tempCell.setAttribute("class", "negative");
works in Mozilla / NS6+ etc, but fails in IE. You can get around it by using:

Code:
tempCell.className = "negative";
HTH,

Chris

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old July 22nd, 2004, 05:58 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Chris, it works.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
change color of background meena88 C# 2005 1 November 6th, 2007 06:00 AM
change background color of toolbar control myth12345 VB How-To 1 January 6th, 2005 12:25 AM
Change the background color of a msgbox nobreferreira VB.NET 2002/2003 Basics 3 October 28th, 2004 10:37 AM
change background color of cell based on value vurtman ASP.NET 1.0 and 1.1 Basics 4 February 26th, 2004 03:52 PM
change background color of inputbox vickriz Javascript How-To 2 July 1st, 2003 10:36 AM



All times are GMT -4. The time now is 03:51 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc