Solved

changing the background image of td onblur

Posted on 2004-09-27
6
699 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

910 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

21 Experts available now in Live!

Get 1:1 Help Now