OnClick and change color

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nma
    New Member
    • Aug 2007
    • 93

    OnClick and change color

    Hi
    How do I make the cell change color to 'black' after I click on it. The cell will remain black color until I click another cell which will also change to black. I can do the mouseover and mouseout correctly only to make it change color to black once I click on it.

    Could someone help?

    Thansk
    nma

    [PHP]
    <td width="<?php echo ($cellwidth); ?>" height="17" bgcolor="#00ff0 0" onMouseOver="th is.style.backgr ound ='red'"
    onMouseOut="thi s.style.backgro und='#00ff00'" onClick="window .frames.eventsD isplay.location = 'MB2eventlistTi meline.php?movi eID=<?php echo $movie->movieID;?>&eve nts=<?php echo $timeline->eventCategory; ?>#<?php echo $timeline->eventID?>'; parent.notesFor m.eventID.value =<?php echo $timeline->eventID?>;pare nt.resetNotes() ;this.style.bac kgroundColor='b lack';" style="cursor: pointer;"></td>


    [/PHP]
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    If you set the background onclick the onmouseout will change the background colour again. You will need to set a variable and check for this onmouseout if you want to avoid this.

    Comment

    • nma
      New Member
      • Aug 2007
      • 93

      #3
      Originally posted by acoder
      If you set the background onclick the onmouseout will change the background colour again. You will need to set a variable and check for this onmouseout if you want to avoid this.
      Hi acoder

      I don't really get you. What should I do?

      Nma

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by nma
        Hi acoder

        I don't really get you. What should I do?

        Nma
        Assuming that that is the problem, declare a global variable, say clicked, to false. Then in the onclick add "clicked = false;". In onmouseout add "if (!clicked)" at the beginning so that if it's been clicked the mouse-out will not change the black background.

        Comment

        Working...