javascript timer to cgi

Discussion in 'Javascript' started by jason_box, May 4, 2006.

  1. jason_box

    jason_box Guest

    Hello, I was wondering if there was a way to have a javacript be
    activated by an input button that would call to a cgi program and
    querey every 10minutes and the cgi would update the page without
    additional user interaction. I found some timer stuff in js but it had
    to do with delays and not what I was really looking for. Thank you in
    advanced.
     
    jason_box, May 4, 2006
    #1
    1. Advertising

  2. jason_box

    Evertjan. Guest

    jason_box wrote on 05 mei 2006 in comp.lang.javascript:

    > Hello, I was wondering if there was a way to have a javacript be
    > activated by an input button that would call to a cgi program and
    > querey every 10minutes and the cgi would update the page without
    > additional user interaction. I found some timer stuff in js but it had
    > to do with delays and not what I was really looking for.


    But ....

    CGI works on the server, and updating a page is done by the client.

    The CGI programme cannot press a clientside button, so the user has to
    presss it every 10 minutes?

    Where do you want the javascript to run?

    On the client browser, or on the server [under ASP]?

    What is the difference between waiting and a delay?

    > Thank you in advanced.


    Not that advanced I hope.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., May 4, 2006
    #2
    1. Advertising

  3. jason_box

    jason_box Guest

    Hello, Thank you for your quick response. I should clarify myself if my
    question was a little confusion. The cgi script just calls to a local
    server to output some data from the server which works. On the html
    page I wanted a javascript that would be activiated and call the cgi
    program and call to the cgi every 5-10minutes. The cgi will already
    outputs the data to the main html page but I would like it to be only
    active when a user wants the data. Since I do not want to over request
    from the server, the javascript should just call to the cgi every
    10minutes until the user press a stop button whcih cuases the
    javascript to stop. I think this can be done with on() and off()
    functions but I was not sure how to do this yet. The javascript will be
    ran through the client side so of course it will require some
    interaction. I hope this clears up any confusion. Thank you again.


    Evertjan. wrote:
    > jason_box wrote on 05 mei 2006 in comp.lang.javascript:
    >
    > > Hello, I was wondering if there was a way to have a javacript be
    > > activated by an input button that would call to a cgi program and
    > > querey every 10minutes and the cgi would update the page without
    > > additional user interaction. I found some timer stuff in js but it had
    > > to do with delays and not what I was really looking for.

    >
    > But ....
    >
    > CGI works on the server, and updating a page is done by the client.
    >
    > The CGI programme cannot press a clientside button, so the user has to
    > presss it every 10 minutes?
    >
    > Where do you want the javascript to run?
    >
    > On the client browser, or on the server [under ASP]?
    >
    > What is the difference between waiting and a delay?
    >
    > > Thank you in advanced.

    >
    > Not that advanced I hope.
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)
     
    jason_box, May 4, 2006
    #3
  4. jason_box

    Evertjan. Guest

    jason_box wrote on 05 mei 2006 in comp.lang.javascript:

    > Hello, Thank you for your quick response. I should clarify myself if my
    > question was a little confusion. The cgi script just calls to a local
    > server to output some data from the server which works. On the html
    > page I wanted a javascript that would be activiated and call the cgi
    > program and call to the cgi every 5-10minutes. The cgi will already
    > outputs the data to the main html page but I would like it to be only
    > active when a user wants the data. Since I do not want to over request
    > from the server, the javascript should just call to the cgi every
    > 10minutes until the user press a stop button whcih cuases the
    > javascript to stop. I think this can be done with on() and off()
    > functions but I was not sure how to do this yet. The javascript will be
    > ran through the client side so of course it will require some
    > interaction. I hope this clears up any confusion. Thank you again.


    [please do not toppost on usenet]


    <button
    onclick='var tmt = setInterval("doCallServer()",10*60*1000)'>
    start</button>

    <button onclick='clearInterval(tmt)'>
    stop</button>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., May 4, 2006
    #4
  5. jason_box

    jason_box Guest

    > <button
    > onclick='var tmt = setInterval("doCallServer()",10*60*1000)'>
    > start</button>
    >
    > <button onclick='clearInterval(tmt)'>
    > stop</button>


    Which part of the segment of code do I make the call to the cgi
    program?
    I was thinking of using general input forms and have it submit and post
    to cgi, but that would still leave me with the timing issue.

    Also on another note, on this line

    > onclick='var tmt = setInterval("doCallServer()",10*60*1000)'>


    10*60*1000, what units is this in?

    Thank you.
     
    jason_box, May 5, 2006
    #5
  6. jason_box

    ASM Guest

    jason_box a écrit :
    >><button
    >>onclick='var tmt = setInterval("doCallServer()",10*60*1000)'>
    >>start</button>
    >>
    >><button onclick='clearInterval(tmt)'>
    >>stop</button>

    >
    >
    > Which part of the segment of code do I make the call to the cgi
    > program?


    you'll need to create your function doCallServer()

    i.e : to submit your form nammed 'myForm'

    function doCallServer() {
    document.forms['myForm'].submit();
    }

    > I was thinking of using general input forms and have it submit and post
    > to cgi, but that would still leave me with the timing issue.


    The problem will be : on datas sent back from your cgi
    the start button will have to be pushed again.
    Perhaps could you send with theses datas some JS script to automatically
    re-start the timer

    <script type="text/javascript">
    var tmt;
    onload = function() {
    tmt = setInterval("doCallServer()",10*60*1000);
    }
    </script>

    >>onclick='var tmt = setInterval("doCallServer()",10*60*1000)'>

    >
    > 10*60*1000, what units is this in?


    milliseconds (here : 10 minutes)



    --
    Stephane Moriaux et son [moins] vieux Mac
     
    ASM, May 5, 2006
    #6
  7. jason_box

    Randy Webb Guest

    jason_box said the following on 5/4/2006 9:04 PM:
    >> <button
    >> onclick='var tmt = setInterval("doCallServer()",10*60*1000)'>
    >> start</button>
    >>
    >> <button onclick='clearInterval(tmt)'>
    >> stop</button>

    >
    > Which part of the segment of code do I make the call to the cgi
    > program?


    In the doCallServer() function.

    > I was thinking of using general input forms and have it submit and post
    > to cgi, but that would still leave me with the timing issue.


    No, setInterval sets that timer. Whether you had a timing issue or not
    (and how you solved it) would depend on how you update the page.

    > Also on another note, on this line
    >
    >> onclick='var tmt = setInterval("doCallServer()",10*60*1000)'>

    >
    > 10*60*1000, what units is this in?


    milliseconds and should probably be hard coded as 600000 instead of the
    browser doing multiplication every time.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, May 5, 2006
    #7
  8. jason_box

    jason_box Guest

    >you'll need to create your function doCallServer()

    >i.e : to submit your form nammed 'myForm'


    >function doCallServer() {
    >document.forms['myForm'].submit();


    >}



    I think I got a little confused with this. The javascript will handle
    the timing of calling to the cgi script, so when the button is pressed,
    it triggers the event to the cgi and the javascript can be made so that
    it will call the script x-mount of minutes. Now I can see what the
    doCallServer() would do, but I'm confused on why a
    documents.form['myForm'].submit() would be needed? Wouldn't that mean I
    have a form with data to pass to the cgi? In my case I have no data to
    pass to the cgi, I only call to it and it does its job and I just need
    to know the segment of code that will return the location of where the
    output will be on the main index.html page. Thank you all again for
    your time and explanations.
     
    jason_box, May 5, 2006
    #8
  9. jason_box

    Evertjan. Guest

    Randy Webb wrote on 05 mei 2006 in comp.lang.javascript:

    >>> onclick='var tmt = setInterval("doCallServer()",10*60*1000)'>

    >>
    >> 10*60*1000, what units is this in?

    >
    > milliseconds and should probably be hard coded as 600000 instead of the
    > browser doing multiplication every time.
    >


    This multiplication is done only when clicked, so probably far less than
    every 10 minutes. The setInterval() does not recalculate, but stores the
    result, I presume.

    For educational purposes, I prefer 10*60*1000 in this NG.

    [As John Stockton so often remarked, 6e5 would be the best notation.]

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., May 5, 2006
    #9
  10. jason_box

    ASM Guest

    jason_box a écrit :
    >>you'll need to create your function doCallServer()

    >
    >>i.e : to submit your form nammed 'myForm'

    >
    >>function doCallServer() {
    >>document.forms['myForm'].submit(); }

    >
    > I think I got a little confused with this. The javascript will handle
    > the timing of calling to the cgi script, so when the button is pressed,
    > it triggers the event to the cgi and the javascript can be made so that
    > it will call the script x-mount of minutes.


    I have a little problem with your deal :
    "javacript be activated by an input button that would call to a cgi
    program and querey every 10minutes and the cgi would update the page"
    here ___________________________________________^^^^^^^^^^^^^^^^^^^^^

    As I unterstand your cgi loads back same page (with some adds on?)
    On each new load the previous Javascript is forgotten ... :-(

    If you need a JavaScript to update sequentially a page, this page has to
    be displayed in an other viewport (window or frame or iframe).

    You may also use XMLHttpRequest to modify (on the fly) a part of your
    page but this way of doing is not very easy, overall if you aren't
    familiar with JavaScript.

    ask XMLHttpRequest to Google

    > Now I can see what the
    > doCallServer() would do, but I'm confused on why a
    > documents.form['myForm'].submit() would be needed?


    That is an answer to your precedent post where you talk about form.

    > Wouldn't that mean I
    > have a form with data to pass to the cgi? In my case I have no data to
    > pass to the cgi, I only call to it


    To call it you need a button with an onclick or a link or an action's
    form, no ?

    > and it does its job and I just need
    > to know the segment of code that will return the location of where the
    > output will be on the main index.html page.



    <html>
    <h1>my main page</h1>
    <form>
    <input type=button name="start" value="Start"
    onclick="if(parent.myFrame)
    tmp=setInterval('parent.myFrame.location=\'/cgi/foo.cgi\'',600000);
    else alert('browser non compatible');
    this.disabled=true;
    stop.disabled=false;
    ">
    <input type=button name="stop" value="Stop" disabled
    onclick="clearInterval(tmp);
    this.disabled=true;
    start.disabled=false;">
    </form>
    <iframe name="myFrame" src="/cgi/foo.cgi" width=500 height=400>
    Your browser doesn't know iframes, click <a href="/cgi/foo.cgi">here</a>
    </iframe>
    </html>

    --
    Stephane Moriaux et son [moins] vieux Mac
     
    ASM, May 5, 2006
    #10
  11. jason_box

    jason_box Guest

    Thank you all for your help. That XMLHttpRequest() object is very
    useful and I also used document.getElementById().innerHTML function
    to specify where I wanted outputted instead of using iFrames. I've had
    issues with iframes in the past, but they were useful for a site I
    built a year back. Thanks again, I got my script to work perfect now.
     
    jason_box, May 5, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kelsang Wangchuk

    System.Timers.Timer vs. System.Threading.Timer

    Kelsang Wangchuk, Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    725
    Kelsang Wangchuk
    Jul 31, 2003
  2. Replies:
    1
    Views:
    1,625
    Steve C. Orr [MVP, MCSD]
    Feb 22, 2005
  3. Simon

    page timer, or redirect timer

    Simon, Nov 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    11,224
    Bruce Barker
    Nov 4, 2005
  4. kloppie
    Replies:
    0
    Views:
    648
    kloppie
    Mar 13, 2007
  5. Replies:
    8
    Views:
    521
    Jorgen Grahn
    Jul 15, 2013
Loading...

Share This Page