• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 749
  • 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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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