Solved

changing the background image of td onblur

Posted on 2004-09-27
6
696 Views
Last Modified: 2012-08-13
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
Comment
Question by:geoenvi
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:viola123
ID: 12165448
really don't understand what you are saying, could u please post more code here?

thanks
viola
0
 

Author Comment

by:geoenvi
ID: 12165464
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
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
ID: 12165495
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:geoenvi
ID: 12165757
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
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 12169464
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
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 12276710
Glad we could help.  Thanks for the A. :^)

Cd&
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now