SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: attach/detach problem.
-
Aug 18, 2002, 10:27 #1
attach/detach problem.
Alright, I've got a problem.
I'm attaching the function hover() to the whole document, which should fire onpropertychange.
Well, but the <option> tag should not be affected by this eventhandler.
Code:
PHP Code:window.onload=Init;
function Init(){
if(document.activeElement){
document.attachEvent("onpropertychange",hover);
option = document.getElementsByTagName("option");
for(j = 0; j < option.length; j++){
document.getElementsByTagName("option")[j].detachEvent("onpropertychange",hover);
}
}
}
May there exist an other possibility to reach the result I'm aiming for?
Thx a lot, and sorry for my bad EnglishLast edited by Toxical; Aug 19, 2002 at 05:57.
I beg your pardon for my bad English
-
Aug 19, 2002, 05:56 #2
Nobody has got an idea??
I beg your pardon for my bad English
-
Aug 19, 2002, 06:29 #3
- Join Date
- Feb 2002
- Location
- Gatwick, UK
- Posts
- 1,206
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
1) How do you know when that function is being run, or if at all... use an alert('running') to check it's being run.
2) put alert('logic') inside the if() clause to check it's getting a reference handle for document.activeElement
3) I can't see the function hover - i take it you simply didn't include it.
Flawless---=| If you're going to buy a pet - get a Shetland Giraffe |=---
-
Aug 19, 2002, 06:29 #4
- Join Date
- Aug 2001
- Location
- London
- Posts
- 2,475
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i dont understand what your trying to do, so do you have a page i can look at to get a better picture of what your attempting.
-
Aug 19, 2002, 08:19 #5
Thx for your answers.
I've got the hover() function includet but it's quite long so i didn't want to post it here, but if you think I should.. no problem
PHP Code:// JavaScript Document
var aktElement=null;
id2value = new Array(3);
id2value["empfaenger"] = "";
id2value["absender"] = "Dein Name";
id2value["email"] = "Deine eMail Adresse";
id2value["message"] = "Deine Nachricht";
window.onload=Init;
function Init(){
if(document.activeElement){
document.attachEvent("onpropertychange",hover);
option = document.getElementsByTagName("option");
for(j = 0; j < option.length; j++){
document.getElementsByTagName("option")[j].detachEvent("onpropertychange",hover);
}
}
}
function hover(){
if(event.propertyName=="activeElement"){
aktElementTagName=document.activeElement.tagName.toLowerCase();
aktElementAttr=document.activeElement.getAttribute("type");
if(aktElement!=null && aktElementId!=null){
aktElement.style.color="#000000"; // Hover zuruecksetzen
aktElement.style.backgroundColor="#ffffff"; // Hover zuruecksetzen
if(aktElement.tagName.toLowerCase()=="select"){
for(i = 0; i<aktElement.options.length; i++){
aktElement.options[i].style.color="#000000"; // Hover zuruecksetzen
aktElement.options[i].style.backgroundColor="#ffffff"; // Hover zuruecksetzen
}
}
//(aktElement.value == '')?aktElement.value=id2value[aktElementId]:0 // Bei leer auf Standart Wert setzen
if(aktElement.value == '' || aktElement.value == id2value[aktElementId]){
eval('document.images.img_' + aktElementId + '.src = "kreuz_s.gif";');
aktElement.value=id2value[aktElementId];
}
else{
eval('document.images.img_' + aktElementId + '.src = "haken_s.gif";');
}
}
if((aktElementTagName=="input" && aktElementAttr=="text") || aktElementTagName=="textarea" || aktElementTagName=="select"){
aktElementId=document.activeElement.id.toLowerCase();
aktElement=document.activeElement;
aktElement.style.color="#000000"; // Textfarbe fuer Hover
aktElement.style.backgroundColor="#EFE4EF"; // Textfeldfarbe fuer Hover
if(aktElementTagName=="select"){
for(i = 0; i<aktElement.options.length; i++){
aktElement.options[i].style.color="#000000"; // Textfarbe fuer Hover
aktElement.options[i].style.backgroundColor="#EFE4EF"; // Textfeldfarbe fuer Hover
}
}
(aktElement.value == id2value[aktElementId])?aktElement.value='':0 // Bei Standart Wert auf leer setzen
}
else{
aktElement=null;
aktElementId=null;
}
}
}
Here's the link.
All elements work except for the select box, and I think that's because, as soon as the first option's bgcolor gets changed, the hover() function fires again.... therefore i wanted the option tag not to react on the eventhandler onpropertychange, don't know for sure if that's the right problem I'm trying to solve...
But I'm sure you'll help me out
Thx
ToxLast edited by Toxical; Aug 20, 2002 at 03:14.
I beg your pardon for my bad English
-
Aug 22, 2002, 08:16 #6
- Join Date
- Jan 2002
- Location
- London
- Posts
- 3,509
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Why not change the 5th line of your hover function from this
Code:if(aktElement!=null && aktElementId!=null){
Code:if(aktElement!=null && aktElementId!=null && aktElementTagName!="option"){
MarcusJT
- former ASP web developer / former SPF "ASP Guru"
- *very* old blog with some useful ASP code
- Please think, Google, and search these forums before posting!
Bookmarks