Anyway to delay JS call?

Posted on 2009-04-29
Last Modified: 2012-06-27

This is what I have:
  I have a hidden field on an aspx page. I have a sumbit button. I do a database save on the click event and get an OrderID.
 BUT,on Onclick event of the button, i first call a JS function. When I call this JS, I still dont have the OrderId.

 JS function gets called it, that's why the hidden field is empty.

Anyway to call this JS AFTER I get the orderID??

function ReloadParentPage()

        alert(document.getElementById('ctl00_Body_orderIdHidden').value); //This is EMPTY
      window.opener.location.href = "POrder.aspx?" + document.getElementById('ctl00_Body_orderIdHidden').value;

Question by:Camillia
    LVL 18

    Accepted Solution

    simplest solution is to use setTimeout:

        //  this function will be executed after miliseconds that you give in next parameter

    }, 4000);

    so it will fire this function after 4 sec.
    LVL 12

    Assisted Solution

    by:Gibu George
    setTimeout(" ReloadParentPage()", 1000), this will execute the  ReloadParentPage() function after 1 second
    LVL 18

    Expert Comment

    I would rather never use string as a parameter for setTimeout, setInterval function, because its beeing evaled (that is evil -> read about it on web) :)))
    LVL 7

    Author Comment

    let me try

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article shows how to read a single webpage's HTML into a string variable, and it also shows how to automate a sequence so you can read and process a list of webpages.  I was tasked with reading and parsing a series of webpages to collect some s…
    In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now