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?

2
  • () calls whatever is in front of it. Commented Aug 8, 2013 at 0:04
  • Duplicate of this... Commented Aug 8, 2013 at 0:25

1 Answer 1

8

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

setTimeout(seriesIdOnBlur2, 3000);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.