farhangdon
farhangdon

Reputation: 2003

Loading webpage after some time ASP.net using Javascript

It seems a duplicate but Its taken a lot of time still causing some problem. Kindly someone point out what I am doing wrong.

I have a button, when I click it JS function show() is called

<input type="button" onclick="show()" value="Add to Cart">

The javascript code is below

    function show() {

          document.getElementById("loadingDiv").style.display = "block";

          setTimeout('Redirect()', 2000);
          function Redirect() {
              location.href = 'Index.aspx';
          }


    }

The div is set to block properly but the page never redirects. Not sure whats the issue.

Upvotes: 2

Views: 57

Answers (3)

Shaikh Sirajudeen
Shaikh Sirajudeen

Reputation: 1

change this line setTimeout('Redirect()', 2000); to setTimeout(Redirect(), 2000);

basically in the setTimeout parameter the function name should not be in Quotes

Upvotes: 0

Sindhoo Oad
Sindhoo Oad

Reputation: 1194

try this.

function show() {

      document.getElementById("loadingDiv").style.display = "block";

      setTimeout(function(){
            location.href = 'Index.aspx';
      }, 2000);

}

or create redirect function out of show function body and call it with name not as string.

Upvotes: 1

Olivier De Meulder
Olivier De Meulder

Reputation: 2501

You need to remove the brackets and the single quotes when you call the redirect function.

setTimeout(Redirect, 2000);

Here is the documentation for the setTimeout function.

Upvotes: 3

Related Questions