SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Function broken in IE (no, really)

    In IE the default image shows on page load. However, when clicked it just shows a blank space. I can still click and bring back the default image though.
    Code:
    function toggleImg(img,suff0,suff1) {
    	var src = img.src;
    	img.src = src.indexOf(suff0) > -1
    		? src.replace(suff0,suff1)
    		: src.replace(suff1,suff0);
    }
    
    // HTML CODE
    <a href="javascript:;"><img src="includes/themes/use_image_y.gif" border="0" onclick="toggleImg(this, '_y', '_n'); var el=document.getElementById('useImage"."$name');el.value=(el.value=='0')?'1':'0';" /></a>
    <a href="javascript:;"><img src="includes/themes/use_image_n.gif" border="0" onclick="toggleImg(this, '_n', '_y'); var el=document.getElementById('useImage"."$name');el.value=(el.value=='1')?'0':'1';" /></a>

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried it and it worked for me in ie6.

    One thing - when you click the img tag it calls toggleImg but it still processes the <a> as well, could that be messing it up? Why do you even have the <a> tags wrapped around the img?

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Getting rid of the <a> tags completely should fix it.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had the <a> tags as a visual indicator that it could be clicked. Removing them did the trick! So I've now changed it to style="cursor:hand" and all is fine.

    Thanks!

  5. #5
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use cursorointer for IE 6+ and other new browsers. "Hand" is not really correct.

  6. #6
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    good tip. thanks!


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
  •