Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Javascript - changing font colour of row

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    11
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Javascript - changing font colour of row

    Hi, I need to change the colour of the newly appended rows, although it doesn't seem to be working with what I have.
    Any advice would be good?

    It currently appends a new row, although I need this new row to be 'added' in a green font.

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN? "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <
    head>
        <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <
    title>Lab 5 Task C</title>
            <
    style type="text/css">
                .
    ab 
                
    {
                    
    font-familyVerdanaArialHelveticasans-serif;
                    
    font-sizesmall;
                    
    color#993300;
                    
    background-color#CCFFCC;
                    
    padding5px;
                    
    height100px;
                    
    width350px;
                    
    borderthin dotted #993300;
                
    }
                 .
    green
                
    {
                    
    font-familyVerdanaArialHelveticasans-serif';
                    color: #006600;
                }

                table, th, td
                {
                    border: 1px solid black;
                }

            </style>
            <script type="text/javascript">
            
                    var i = 0;
                    function addressBookItem (fname, lname, email) 
                    {
                        this.fname= fname;
                        this.lname = lname; 
                        this.email = email;
                    }
                                
                    function appendRow()
                    {
                        var fname = prompt("Please enter your first name:","Your name");
                        var lname = prompt("Please enter your last name:","Your last name");
                        var email = prompt("Please enter your email:","Your name");
                        //var adrbook = document.createTextNode("<tr class='
    .green'> <td>" + fname + "</td> <td>" + lname + " </td> <td>" + email + "</td> </tr>");    
                        var table = document.getElementById("addrBook");
                        r = table.insertRow(-1);
                        r.className = "green";
                        c = r.insertCell(0);
                            c.innerHTML = fname;
                        c.className = "normal";
                            c = r.insertCell(1);
                        c.innerHTML = lname;
                            c = r.insertCell(2);
                        c.innerHTML = email;
                        document.body.appendChild(table);
                    }

                    addressBookItem.prototype.write = function() 
                    {
                        var table = document.getElementById('
    addrBook');
                        r = table.insertRow(-1);     
                        c = r.insertCell(0);
                            c.innerHTML = this.fname;
                        c = r.insertCell(1);
                            c.innerHTML = this.lname;
                        c = r.insertCell(2);
                            c.innerHTML = this.email;
                        document.body.appendChild(table);
                    }
            </script>
        </head>
        <body> 
            <script type="text/javascript">
                // table data
                var aB1 = new addressBookItem('
    Roger', 'Williams', 'rwilliams@gmail.com');
                var aB2 = new addressBookItem ('
    Rose', 'Schultz', 'rose_s@earthlink.net');
            
                // create table
                var table = document.createElement("table");
                table.id = "addrBook";
                r = table.insertRow(0); 
                c = r.insertCell(0);
                    c.innerHTML = '
    First Name';
                c = r.insertCell(1);
                    c.innerHTML = '
    Last Name';
                c = r.insertCell(2);
                    c.innerHTML = '
    Email;

                
    document.body.appendChild(table);

                
    aB1.write();
                
    aB2.write();        
            
    </script>
                <input type="button" onclick="appendRow()" value="Append Row">
            </br>
        </body>
    </html> 


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,407
    My Mood
    Mellow
    Thanks
    143
    Thanked 603 Times in 590 Posts

    Default Re: Javascript - changing font colour of row

    Moved to Other Languages.

Similar Threads

  1. Replies: 2
    Last Post: December 12th, 2013, 11:01 PM
  2. [SOLVED] JComponent background colour
    By newbie in forum AWT / Java Swing
    Replies: 6
    Last Post: June 4th, 2012, 08:30 AM
  3. Re: How to Change JTextArea font, font size and color
    By binokyo10 in forum Java Theory & Questions
    Replies: 1
    Last Post: February 5th, 2012, 11:12 AM
  4. How to Change JTextArea font, font size and color
    By Flash in forum Java Swing Tutorials
    Replies: 7
    Last Post: January 14th, 2012, 09:47 PM
  5. How to Change JTextArea font, font size and color
    By Flash in forum Java Code Snippets and Tutorials
    Replies: 4
    Last Post: July 8th, 2008, 01:45 PM