SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    setTimeout not working - are there any javascript experts out there?

    I am new to javascript and cannot get the delay to work. In essence, I want to change an image (name="centerimg") when a user mouses over a link but I want a delay of 2 seconds before it occurs. The image swap is working but the delay does not. I have been staring at this for hours and cannot get it. Please help!

    These are the two functions:

    function wait(img_name,img_src,delay){
    window.setTimeout(changeimg(img_name,img_src),delay);
    }

    function changeimg(img_name,img_src){
    document[img_name].src=img_src;
    }

    This is the call to the function:

    <p><a href="weddings.html" onmouseover="wait('centerimg','images/imagename.jpg',2000);">Link Text</a></p>

  2. #2
    SitePoint Evangelist vikrantkorde's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai, India
    Posts
    541
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    change this line
    window.setTimeout(changeimg(img_name,img_src),delay);
    to
    window.setTimeout("changeimg('"+img_name+"','"+img_src+"')",delay);
    Vikrant Korde
    S Y S T I M E, Mhape,
    Mumbai, Maharashtra, India.

  3. #3
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    That DID IT!

    Thank you so much! That worked.

    I am not exactly sure why but it worked. I guess I have to read about passing parameters between functions!


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
  •