#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Just this side of hell, Tulsa, Oklahoma...
    Posts
    13
    Rep Power
    0

    Javascript: getElementbyId - What do I have???


    Ok...
    Using PHP to write javascript...
    I have code that runs like:

    PHP Code:
    ."function icoswitch(bid)\n"
    ."{\n"
        
    ."icoID = document.getElementById('pic'+bid); \n"
        
    ."alert(\"icoID File is  \"+ icoID.name.property + \" and that is that.\"); \n"
        
    ."if(icoID.src == \"themes/$GLOBALS[thename]/images/minus.gif\") \n"
        
    ."{ \n"
            
    ."icoID.src=\"themes/$GLOBALS[thename]/images/plus.gif\"; \n"
            
    ."alert(\"The icon should be set to PLUS.gif.  \"+icoID.src); \n"
            
    ."SetCookie('block'+bid,'yes',365); \n"
        
    ."}\n"
        
    ."else\n"
        
    ."{\n"
            
    ."icoID.src=\"themes/$GLOBALS[thename]/images/minus.gif\"; \n"
            
    ."alert(\"The icon should be set to MINUS.gif.  \"+icoID.src); \n"
            
    ."DeleteCookie('block'+bid); \n"
        
    ."} \n"
    ."} \n" 
    Again... this is processed to the HTML through PHP... and it is part of a larger whole...

    As you can see... I have set some alerts to help me troubleshoot it. What I am getting is, on the:

    PHP Code:
    ."if(icoID.src == \"themes/$GLOBALS[thename]/images/minus.gif\") \n" 
    It is never going to == the minus.gif... because it equals out to a larger URL... Now I could just put in the rest of the URL, but I really don't want to... I am trying to build something a little more universal... So... How can I get the ACTUAL FILENAME for the javascript variable: icoID

    icoID.name.property doesn't work...
    I have tried icoID.name, icoID.filename, etc...
    Nothing works...

    Can someone point me to the correct DOM? I need to grab the actual FILENAME of the image it is pointing to... not the URL. If I could check the FILENAME then I could verify whether it was + or -...

    If someone can help me out it would be greatly appreciated.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    3
    Rep Power
    0
    I was trying to do something similar, and never found out how to just get the file name. of course you could always split the string to get just the part you want.

    if you are just searching for minus.gif then inStr should work to find that.

    what i ended up doing was storing the filename in the value attribute of a button for the purpose of a hover over image without having to write out the entire url of the hover image, then just replaced 'hover' with nothing for mouseout.

    let me know if this helps

    Nate

IMN logo majestic logo threadwatch logo seochat tools logo