2

I'm trying to set up my onblur so it shows a loading bar for 3 seconds... however the code seems to just miss it out and go straight to the second function...

function seriesIdOnBlur()
{       
    document.getElementById("series_id_check").innerHTML = "<img src='http://www.webscriptlab.com/file/loading/output/13759195689.gif' /> ";

    setTimeout(seriesIdOnBlur2(), 3000);
}

function seriesIdOnBlur2()
{
    var id = document.getElementById("series_id").value;

    var message = "";

    if (series[id] === undefined)
    {
        message = "The Series ID you input was invalid";
    }
    else
    {
        var seriesId = series[id];

        var game = seriesId['game'];
        var name = seriesId['name'];
        message = "ID: " + id + " is for the " + name + " series playing " + game + ".";

    }

    document.getElementById("series_id_check").innerHTML = "<span>" + message + "</span>";
}

seriesIdOnBlur is called onBlur for the input with id series_id.

What am I doing wrong with the setTimeout?

Chris McFarland
  • 6,059
  • 5
  • 43
  • 63
RedJax
  • 123
  • 3
  • 10

1 Answers1

8

You're calling the function and passing the result into setTimeout. You want to pass the function into setTimeout:

setTimeout(seriesIdOnBlur2, 3000);
Blender
  • 289,723
  • 53
  • 439
  • 496