SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast ethe's Avatar
    Join Date
    Oct 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 2 onclick events

    Hi there I have 2 actions that i want to do once the user has clicked on the link.

    <a onclick='return showPic(this)' href='/php/img.php?id=$t&ref=$r' title=''>$t</a>
    <a href="#" onClick="toggleactive(this);return false;">$t</a>

    i also would like that the $t should get the active css class how can i combine this 2 scripts to one ?
    DISPLAY IMAGE

    Code JavaScript:
    function showPic (whichpic) {
     if (document.getElementById) {
      document.getElementById('placeholder').src = whichpic.href;
      if (whichpic.title) {
       document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
      } 
      return false;
     } else {
      return true;
     }
    }


    CHANGE CLASS

    Code JavaScript:
    var currLink = null;  
    function toggleactive(elm) 
    {  
      if(currLink)  
        currLink.className = currLink.className.replace(/\bactive\b/,''); 
      currLink = elm;  
      currLink.className += " active"; 
    }

  2. #2
    SitePoint Zealot GiorgosK's Avatar
    Join Date
    Jun 2007
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not sure this is what you are asking but you can call them one by one

    <a href='/php/img.php?id=$t&ref=$r' onClick="toggleactive(this); showPic(this);return false;">$t</a>

  3. #3
    SitePoint Enthusiast ethe's Avatar
    Join Date
    Oct 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    step by step

    1) the links refer to php file that will get the image out of a db.
    2) once i click on the first link it should pop up with the showPic script
    3) then it should change the class of the link to active

    with the solution you gave me the image doesn't show up on the same page adn no image will be displayed because the image.php triggered

    any suggestions?

  4. #4
    SitePoint Enthusiast ethe's Avatar
    Join Date
    Oct 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    it worked!

    What i did was put the javascript of the class toggle into the show image javascript so now it works thanks to the extra script you gave me !


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
  •