Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

change of cell color

Posted on 2008-10-13
3
Medium Priority
?
312 Views
Last Modified: 2011-04-14
i have a table with bluecolor background.
i want to navigate thru the cells using keyboard and as i move from td to td
i want the current focus td to be of color green. pl help.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
 <body>
<table cellpadding="5" cellspacing="1" border="0">
	<tr bgcolor="#CCCCFF">
			<td tabIndex="1" width="150px" style="background-color:green">fsdfsd</td>
			<td tabIndex="2" width="150px">fsdfds</td>
			<td tabIndex="3" width="150px">fsdfsd</td>
			<td tabIndex="4" width="150px">hghfgh</td>
	</tr>
	<tr bgcolor="#CCCCFF">
			<td tabIndex="5" width="150px">fsdfsd</td>
			<td tabIndex="6" width="150px">fsdfds</td>
			<td tabIndex="7" width="150px">fsdfsd</td>
			<td tabIndex="8" width="150px">hghfgh</td>
	</tr>
 </body>
</html>

Open in new window

0
Comment
Question by:vidhubala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Accepted Solution

by:
sijishJohn earned 1000 total points
ID: 22700781
try this...

HTML

<table cellpadding="5" cellspacing="1" border="0">
            <tr bgcolor="#CCCCFF">
                <td tabindex="1" width="150px" style="background-color: green" onfocus="Green(this);" onblur="Blue(this);">
                    fsdfsd</td>
                <td tabindex="2" width="150px" onfocus="Green(this);" onblur="Blue(this);">
                    fsdfds</td>
                <td tabindex="3" width="150px" onfocus="Green(this);" onblur="Blue(this);">
                    fsdfsd</td>
                <td tabindex="4" width="150px" onfocus="Green(this);" onblur="Blue(this);">
                    hghfgh</td>
            </tr>
            <tr bgcolor="#CCCCFF">
                <td tabindex="5" width="150px" onfocus="Green(this);" onblur="Blue(this);">
                    fsdfsd</td>
                <td tabindex="6" width="150px" onfocus="Green(this);" onblur="Blue(this);">
                    fsdfds</td>
                <td tabindex="7" width="150px" onfocus="Green(this);" onblur="Blue(this);">
                    fsdfsd</td>
                <td tabindex="8" width="150px" onfocus="Green(this);" onblur="Blue(this);">
                    hghfgh</td>
            </tr>
        </table>

SCRIPT

function Green(me)
    {
        me.style.backgroundColor="green";      
    }
   
    function Blue(me)
    {
        me.style.backgroundColor="#CCCCFF";        
    }
0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 1000 total points
ID: 22701186
Hi, can I suggest a more efficient version?
<style>
#t1 tr { background-color:#CCCCFF }
#t1 td {width:150px}
.green {background-color: green; }
.blue {background-color: #CCCCFF; }
</style> 
<script>
window.onload=function() {
  var tb = document.getElementById('t1');
  for (var i=0;i<tb.rows.length;i++) {
    for (var j=0;j<tb.rows[i].cells.length;j++) {
     tb.rows[i].cells[j].onfocus=function() {this.className='green'}
     tb.rows[i].cells[j].onblur=function() {this.className='blue'}
    }
  }
  tb.rows[0].cells[0].focus();
}
</script>
<table id="t1" cellpadding="5" cellspacing="1" border="0">
            <tr>
                <td tabindex="1" class="green">
                    fsdfsd</td>
                <td tabindex="2">
                    fsdfds</td>
                <td tabindex="3">
                    fsdfsd</td>
                <td tabindex="4">
                    hghfgh</td>
            </tr>
            <tr>
                <td tabindex="5">
                    fsdfsd</td>
                <td tabindex="6">
                    fsdfds</td>
                <td tabindex="7">
                    fsdfsd</td>
                <td tabindex="8">
                    hghfgh</td>
            </tr>
        </table>

Open in new window

0
 

Author Closing Comment

by:vidhubala
ID: 31407044
thanks guys
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question