SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What wrong with this simple swap img?

    Code:
    <script language="JavaScript" type="text/JavaScript">
    function SwapImg (name, action) {
    if(action == "out"){
    eval("document."+name+".src=\"images/sq_false.gif\"");
    }if(action == "over"){
    eval("document."+name+".src=\"images/sq_true.gif\"");
    }if(action == "click"){
    eval("document."+name+".src=\"images/sq_true.gif\"");
    }
    }
    </script>
    And i use it like
    Code:
      <tr>
    					<td><img src="images/sq_false.gif" name="sq" width="7" height="7" border="0" /></td>
    					<td><a href="<?php echo $_SERVER['PHP_SELF']."?&nav=works&subNav=done"; ?>" onMouseOver="SwapImg ('sq','over')" onMouseOut="SwapImg ('sq','out')"><img src="images/done_false.gif" border="0" ></a></td>
    		 </tr>
    My questions:
    1/ How would i use "action==click" by which the over-stated is retained?
    2/ Why do i get an error message when i create the A href dynamicly like

    Code:
     <td width="7"><img src="images/sq_false.gif" name="<?php echo $row['id']; ?>" width="7" height="7" border="0"/></td>
       <td class="regularText"><a href="<?php echo $_SERVER['PHP_SELF']."?&nav=works&subNav=".$subNav."&slct=".$row['id']; ?>" onMouseOver="SwapImg ('<?php echo $row['id']; ?>','over')" onMouseOut="SwapImg ('<?php echo $row['id']; ?>','out')"><?php echo $row['worksNme']; ?></a></td>
    It generates:
    Code:
    <td width="7"><img src="images/sq_false.gif" name="11" width="7" height="7" border="0"/></td>
       <td class="regularText"><a href="content.php?&nav=works&subNav=doing&slct=11" onMouseOver="SwapImg ('11','over')" onMouseOut="SwapImg ('11','out')">Test </a></td>
    Any ideas

  2. #2
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You can't use a number as a unique identifier:

    <td width="7"><img src="images/sq_false.gif" name="11"

    You can do something like this:
    <td width="7"><img src="images/sq_false.gif" name="n11"

    In your php do this:
    <img src="images/sq_false.gif"
    name="<?php echo 'n'.$row['id']; ?>"

    Your script can be cleaned up a bit too:
    Code:
    <script type="text/javascript">
    function SwapImg (name, action) {
     switch(action)
     {
      case "out":
      document.images[name].src = "images/sq_false.gif";
      break;
      case "over":
      case "click":
      document.images[name].src = "images/sq_true.gif";
      break; 
     }
    }
    </script>
    -xDev

  3. #3
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thnks xDev,

    Didn't realise you can't use number as a unique identifier. Also thanks for the clean-up.

    On roll-over works now, but retaining the on roll-over state doesn't. Could you tell me how i can "listen" to the action=click ?

    Grtz,

  4. #4
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by D-flyer
    On roll-over works now, but retaining the on roll-over state doesn't. Could you tell me how i can "listen" to the action=click ?
    Grtz,
    Didn't I already show you how to keep the onclick on dynamic pages here?
    http://www.sitepointforums.com/showthread.php?t=137266

    It's the same methodology once again. Javascript is client-side, DHTML can
    only work if the page isn't reloaded or if you are using frames to reload, there
    is no persistence (continuance of an effect after the cause is removed)
    between pages unless you resort to chopping up the search
    string on every page: location.search. But why do that when you're already
    using php? That's one of the key jobs for a server-side language - responding
    to requests

    -xDev


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
  •