• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 742
  • Last Modified:

changing the background image of td onblur

Here is a simplified version of my problem:  My code is too long to paste but will do it if anyone needs it

I have a table with say 4 cells (td1,td2,td3,td4)

I am changing the background image of td1  like this:
In the onclick event, I change td1 background image to "Selected" if image="unselected" and unselected=if image=selected
In the onblur event, I did the same because I want only one cell to be "selected". SO for example, of td2 is selected, then the rest are all unselected along with td1 after I move the focus away from it.

---All the above works FINE**

Now the problem:
I also have a bunch of other controls/images in the page and if I click on them, sure enough the onblur event for the td elements is fired and the selected td becomes unselected.  How do I avoid this?

I tried the following so that you know;
tried decalring a variable to tell me what is clicked and in the onblur event handler for tds, tried to change the image only when the variable contains the td ID BUT obviously, the variable is not set to anything else because the onblur occurs first.

So what do I do?

I do not want that to happen
0
geoenvi
Asked:
geoenvi
  • 3
  • 2
1 Solution
 
viola123Commented:
really don't understand what you are saying, could u please post more code here?

thanks
viola
0
 
geoenviAuthor Commented:
ok let me simplfy the question:
IS there anyway of knowing what element lostfocus and what element gotfocus in the onblur event.

I am not trying to be a smartass here but I am not sure that pasting the code really helps because it is a little complicated to go through and uses ActiveX control rights to manioulate DOM elements
0
 
COBOLdinosaurCommented:
When you fire the onfocus clear the last one you set instead of using the on blur

if as part of the onfocus you set the handle you can clear the previous setting:

onfocus="if (thetd=='selected') { etc} thetd=this; if(thetd=='selected')etc"


Cd&
0
Independent Software Vendors: 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!

 
geoenviAuthor Commented:
I did try the onfocus event but my problem is how will I know what td has lostfocus?  In the absence of that, all I can do is to blindly set every other td other than the one that is currently receiving focus to unselect.  This will be a major pain in my case because each of the tds has a different BG image that are in turn loaded by script depending on user access.  FYI- I have 14 cells and each cell can have upto 3 different images.

My ideal solution would be to know what td has lost focus when I click on another td...
0
 
COBOLdinosaurCommented:
thetd=this;

Sets thetd to the node object of the cell you are focusing on it has all te properties of that cell.

so when you focus on a cell it is a three operations deal:

onfocus="if (thetd && thetd.selected) whatever code you need to unselect the last cell;
Then the second instruction thetd=this; make thetd an alias for the current cell;
finally you do the code you need to set the cell selected.

The variable thetd will always be a handle to the last cell selected except when the page first loads and nothing has ben selected yet. the variable thetd should be created global in the head with thetd=false;

Cd&
0
 
COBOLdinosaurCommented:
Glad we could help.  Thanks for the A. :^)

Cd&
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now