SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot rrreview's Avatar
    Join Date
    Jul 2002
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question on click change cell bgcolor...help?

    To start off, I'm not a Javascript programmer. So I don't really know what I'm doing. Here's what I want to do, though - user clicks a row, row changes color, user clicks row again, it changes back to original color. I don't want any checkboxes or radio buttons either

    Here's my code (which doesn't work).
    Code:
    <SCRIPT Language="Javascript">
     function highlightTable()
     {
     var i;
     i=2;
     
        if (i % 2) {
     	  this.bgcolor='#FF0000';
     	  i++;
        } else {
     	  this.bgcolor='#FFFFFF';
     	  i++;
        }
     }
     </SCRIPT>
     
     ...
     
     <tr bgcolor="#FFFFFF" onClick="highlightTable(); return TRUE">
    In PHP, the % sign is mathematical...returns true if a whole number is returned, returns false if a decimal number is returned.

    Should be pretty simple, but once again, I don't want a checkbox or radio button.

  2. #2
    SitePoint Zealot rrreview's Avatar
    Join Date
    Jul 2002
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess no one responded, which is kind of sad...I've been working on this script for about 2 hours and finally got it. I'll post the code for those who don't have the time that I didn't have.

    Code:
    <script language="JavaScript">
     <!--
     var i = 1;
     function chgBg(obj){
     var color;
     
     if (i % 2) {
       color='#DDDDDD';
       i++;
     }
     else {
       color='#FFFFFF';
       i++;
     }
     
        if (document.all || document.getElementById)
     	 obj.style.backgroundColor=color;
        else if (document.layers)
     	 obj.bgColor=color;
     }
     //-->
     </script>
      
      ...
      
      <tr bgcolor="#FFFFFF" onClick="chgBg(this)">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •