[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

changing the background image of td onblur

Posted on 2004-09-27
6
Medium Priority
?
739 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

649 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