473,386 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Color remains the same after onClick

93
Hi

Can anyone help me..
How can I make onClick color remains the same =red?
Currently if it is mouseover it change to red, onmouseover it change to original background color. I need it to remain red once it is click so that I know where is the last location I click on the bar


[PHP]

<td width="<?php echo ($cellwidth); ?>" height="17" bgcolor="yellow" onMouseOver="this.style.background ='red'"
onMouseOut="this.style.background='yellow'" onClick="window.frames.eventsDisplay.location = 'MB2eventlistTimeline.php?movieID=<?php echo $movie->movieID;?>&events=<?php echo $timeline->eventCategory;?>#<?php echo $timeline->eventID?>';parent.notesForm.eventID.value=<?php echo $timeline->eventID?>;parent.resetNotes();" style="cursor: pointer;"></td>

[/PHP]

Stuck..

nma
Sep 12 '08 #1
8 2355
acoder
16,027 Expert Mod 8TB
You can set a variable onclick which you can test onmouseover.
Sep 12 '08 #2
iam_clint
1,208 Expert 1GB
You could use a custom attribute to know which are selected..


Toggle color on/off with mouseover and mouseout events included.. Example provided
Expand|Select|Wrap|Line Numbers
  1. <table>
  2. <tr>
  3.     <td 
  4.       onmouseover="if (this.getAttribute('selected')==null) { this.setAttribute('selected', ''); } if (this.getAttribute('selected')=='') { this.style.color = '#ff0000'; }"
  5.       onmouseout="if (this.getAttribute('selected')=='') { this.style.color = ''; }"
  6.       onclick="if (this.getAttribute('selected')!='') { this.setAttribute('selected', ''); this.style.color=''; } else { this.setAttribute('selected', 'true'); this.style.color='#ff0000'; }"
  7.       style="cursor: pointer;">
  8.     Blah
  9.     </td>
  10. </tr>
  11. </table>
  12.  
I made this sample with font color rather than background color... you can change it.
Sep 12 '08 #3
nma
93
You could use a custom attribute to know which are selected..


Toggle color on/off with mouseover and mouseout events included.. Example provided
Expand|Select|Wrap|Line Numbers
  1. <table>
  2. <tr>
  3.     <td 
  4.       onmouseover="if (this.getAttribute('selected')==null) { this.setAttribute('selected', ''); } if (this.getAttribute('selected')=='') { this.style.color = '#ff0000'; }"
  5.       onmouseout="if (this.getAttribute('selected')=='') { this.style.color = ''; }"
  6.       onclick="if (this.getAttribute('selected')!='') { this.setAttribute('selected', ''); this.style.color=''; } else { this.setAttribute('selected', 'true'); this.style.color='#ff0000'; }"
  7.       style="cursor: pointer;">
  8.     Blah
  9.     </td>
  10. </tr>
  11. </table>
  12.  
I made this sample with font color rather than background color... you can change it.
Hi iam_clint
I'm correcting the codes like below..there is red color on the cell once I mouseout but it remains many red color appear depending on as many times I click on the cell.
What is wrong with the code?
Thanks

[PHP]
<td width="<?php echo ($cellwidth); ?>" height="17" bgcolor="#00ff00" onmouseover="if (this.getAttribute('selected')==null) { this.setAttribute('selected', ''); } if (this.getAttribute('selected')=='') { this.style.background = '#ff0000'; }" onmouseout="if (this.getAttribute('selected')=='') { this.style.background = ''; }" onclick="if (this.getAttribute('selected')!='') { this.setAttribute('selected', ''); this.style.background=''; } else { this.setAttribute('selected', 'true'); this.style.background='#ff0000'; } "window.frames.eventsDisplay.location = 'MB2eventlistTimeline.php?movieID=<?php echo $movie->movieID;?>&events=<?php echo $timeline->eventCategory;?>#<?php echo $timeline->eventID?>'; parent.notesForm.eventID.value=<?php echo $timeline->eventID?>;parent.resetNotes(); " style="cursor: pointer;"></td>
[/PHP]
Sep 15 '08 #4
iam_clint
1,208 Expert 1GB
I don't fully understand your english... are you trying to make it so only 1 cell can be selected at a time?
Sep 15 '08 #5
nma
93
I don't fully understand your english... are you trying to make it so only 1 cell can be selected at a time?
Sorry for my poor explaination..
Yes I want it only at one time cell selected (say red color)..then when user click at another cell that current cell will be selected and the previous cell back to original color

It is actually a timeline bar...

p/s the code you give is correct in terms of highlighted number of click user made on the timeline show red colored cell appear along the timeline/cells

Please help..
Sep 15 '08 #6
iam_clint
1,208 Expert 1GB
so you need to make a function for onclick.. in this function you iterate through all cells..

Example
Expand|Select|Wrap|Line Numbers
  1. function resetHighlight() {
  2.     var ex=document.getElementById("tablebody").getElementsByTagName("TD"); 
  3.     for (var i=0; i<ex.length; i++) {
  4.         if (ex[i].getAttribute("selected")!="") {
  5.             ex[i].style.background="";
  6.             ex[i].setAttribute("selected", "");
  7.         }
  8.     }
  9. }
  10.  
  11. function highlight(obj) {
  12.     resetHighlight();
  13.     obj.setAttribute("selected", "true");
  14.     obj.style.background="#FF0000";
  15. }
  16.  
Sep 15 '08 #7
nma
93
so you need to make a function for onclick.. in this function you iterate through all cells..

Example
Expand|Select|Wrap|Line Numbers
  1. function resetHighlight() {
  2.     var ex=document.getElementById("tablebody").getElementsByTagName("TD"); 
  3.     for (var i=0; i<ex.length; i++) {
  4.         if (ex[i].getAttribute("selected")!="") {
  5.             ex[i].style.background="";
  6.             ex[i].setAttribute("selected", "");
  7.         }
  8.     }
  9. }
  10.  
  11. function highlight(obj) {
  12.     resetHighlight();
  13.     obj.setAttribute("selected", "true");
  14.     obj.style.background="#FF0000";
  15. }
  16.  
Hi iam_clint,
But how am I going to insert in my original coding..does this function need to be declare somewhere in the beginning of my codes.
At the moment in my original codes when onClick happen it will get some event (video keyframe list). Can I combine this two event (the code you give above + the one in my original codes) within one single onClick lines of codes?


Expand|Select|Wrap|Line Numbers
  1.  
  2. ........onClick="window.frames.eventsDisplay.location = 'MB2eventlistTimeline.php?movieID=<?php echo $movie->movieID;?>&events=<?php echo $timeline->eventCategory;?>#<?php echo $timeline->eventID?>';parent.notesForm.eventID.value=<?php echo $timeline->eventID?>;parent.resetNotes();"...........
Sep 16 '08 #8
acoder
16,027 Expert Mod 8TB
Yes, it's relatively easy to combine. Move all the onclick code into its own function. I see that you're using PHP code within the onclick, so make the function generic and pass the PHP values as arguments to the function.
Sep 18 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Matt Adams | last post by:
As well known I could specify the text color in the body tag like: <BODY TEXT=WHITE LINK=WHITE VLINK=RED ALINK=WHITE> What I want to achieve now is that always (!) the text of the last visited...
15
by: | last post by:
Just about finished with an include modual that allows a user to select a color. Completely dynamic. all you have to do is include the script and run the main trigger script. One problem with...
4
by: RobG | last post by:
I have a function whose parameter is a reference the element that called it: function someFunction(el) { ... } The function is assigned to the onclick event of some elements in the HTML...
1
by: mrajanikrishna | last post by:
Hello, I am developing an application in which the user has to select his choice of colors and displaying the images with that color. How can I display color palette to the user and return the...
1
by: emailseshu | last post by:
Hi, Iam trying to check the Client Side CallBack Feature in ASP.NET Iam able to call th RaiseCallbackEvent from the Client Side Javascript Function but when I go to the debug mode to check the...
3
by: pleaseexplaintome_2 | last post by:
using the code below (some parts not included), I create a new excel workbook with spreadheets. I then want to delete a spreadsheet, but a reference remains open and excel stays in task manager...
2
by: querry | last post by:
Hi all, I am having a table and I am trying to color the border of a cell when it is clicked. Here is what I use as my javascript. function cellColor(tcid, e) { var...
2
by: rathour | last post by:
<?php session_start(); require_once('db.php'); include('functions.php'); $user = get_username ( $_SESSION ); //if ( $_SESSION ): checkLogin ( '1 2' ); ?>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.