SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member Toxical's Avatar
    Join Date
    Apr 2002
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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(
    0option.lengthj++){
              
    document.getElementsByTagName("option")[j].detachEvent("onpropertychange",hover);
            }
        }

    doesn't work unfortunately...

    May there exist an other possibility to reach the result I'm aiming for?

    Thx a lot, and sorry for my bad English
    Last edited by Toxical; Aug 19, 2002 at 04:57.
    I beg your pardon for my bad English

  2. #2
    SitePoint Member Toxical's Avatar
    Join Date
    Apr 2002
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nobody has got an idea??

    I beg your pardon for my bad English

  3. #3
    Perl/Mason Guru Flawless_koder's Avatar
    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 |=---

  4. #4
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    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.

  5. #5
    SitePoint Member Toxical's Avatar
    Join Date
    Apr 2002
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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(
    0option.lengthj++){
              
    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(
    0i<aktElement.options.lengthi++){
                      
    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(
    0i<aktElement.options.lengthi++){
                    
    aktElement.options[i].style.color="#000000";  // Textfarbe fuer Hover
                    
    aktElement.options[i].style.backgroundColor="#EFE4EF"// Textfeldfarbe fuer Hover
                    
    }              
                  }
                  (
    aktElement.value == id2value[aktElementId])?aktElement.value='':// Bei Standart Wert auf leer setzen
              
    }
              else{
                  
    aktElement=null;
                  
    aktElementId=null;
              }
          }

    Is supposed to mark the selected form element

    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
    Tox
    Last edited by Toxical; Aug 20, 2002 at 02:14.
    I beg your pardon for my bad English

  6. #6
    The doctor is in... silver trophy MarcusJT's Avatar
    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){
    to this
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •