Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript changing images problem

    I want to change the image when clicked, and then change back when clicked again.

    it changes the first time, but then doesnt change back

    function:
    Code:
    	function changeplus(theid){
    	var theid=document.getElementById(theid);
    	theid.src=(theid.src=='Images/moredetailminus.gif')? 'Images/moredetailplus.gif' : 'Images/moredetailminus.gif';
    	}
    body:
    PHP Code:
    <span onClick="updatenewsdisplay(<?=$row2['id']?>); 
    changeplus('<?=$row2['id']?>plus');" 
    style="cursor:help; color: #006699;">
    <img id="<?=$row2['id']?>plus" src="Images/moredetailplus.gif"></span>
    any ideas why it isnt working?

    Thankyou!!!
    Last edited by replicah; 07-08-2005 at 05:15 AM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    When you read the src of the image, it returns the absolute path even if you set it to a relative path. So you need to change the condition to:

    Code:
    theid.src=(theid.src.indexOf('minus.gif')!=-1)? 'Images/moredetailplus.gif' : 'Images/moredetailminus.gif';
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thankyou,!! you are awesome!

    can you explain to me what indexOf means and why the -1 in there?

    thanks,
    Daniel.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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