Results 1 to 5 of 5

Thread: Dynamic input value with continue refresh

  1. #1
    Join Date
    Jun 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamic input value with continue refresh

    Hi,

    I have a question to a problem on which I can't find a solution on the net.
    Here's the problem:
    I have a page with two forms. The first form asks the user to fill in some stuff (it doesn't matter what in this case).
    The second form displays several values of a server (like how many packets are send, on-line time etc.). Now I want those values to be refreshed continually without the upper form (or whole page) to refresh. I might do this with an iframe but first I'm looking for a better solution. Next I'll display a fake example:

    <html>
    <body>
    <form name="form1" id="form1" method="post">
    <input type="text" name="username"> fill in your username<br>
    <input type="submit" value="submit">
    </form>
    <form name="form2" id="form2">
    <input type="text" name="packets" value=""> <-- This value should be refeshed with javascript!
    </form>
    </body>
    </html>

    Thanks in advance,

    Miroen

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <html>
    <head>
    <script type="text/javascript">
    var inc=0, beginUp
    function upPackets(){
    document.form2.packets.value=inc;
    inc++
    if (inc>=1000)
    clearInterval(beginUp);
    }
    
    function startUp(){
    beginUp=setInterval('upPackets()',500)
    }
    </script>
    </head>
    <body onload="startUp()">
    <form name="form1" id="form1" method="post">
    <input type="text" name="username"> fill in your username<br>
    <input type="submit" value="submit">
    </form>
    <form name="form2" id="form2">
    <input type="text" name="packets" value=""> <-- This value should be refreshed with javascript! 
    </form>
    </body>
    </html>
    I only included the clearInterval to prevent an overflow situation which would arise if this script were otherwise left running in the background. But, it also illustrates a mechanism by which updating could be suspended if need be. The code you use to make the packet count available to the script is up to you as, I have no idea how to count packets. The value '500' is the number of milliseconds between each iteration of the upPackets function (half a second, in this case).
    Last edited by jscheuer1; 06-30-2005 at 09:32 AM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks John,

    It works! (of course, you'ld say...).

    Miroen

  4. #4
    Join Date
    Jun 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi there,
    I have an extention on this one...
    I would like the "packets" to show a variable which has to be taken form a server.
    I imagine the above code would look like:

    function upPackets(){
    document.form2.packets.value=GET(some value);
    inc++
    if (inc>=1000)
    clearInterval(beginUp);
    }

    Any idea how to do this?

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That requires PHP, xml (neither of which I am familiar with) or some other server side language. Find out from your host what server side languages are available to you and how to access variables on the server using one and get back to me and/or start a fresh post in the PHP or Other forum. I have worked these kinds of things out before but, only when the person asking the question knew how to access the variable needed.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •