PDA

View Full Version : Dynamic input value with continue refresh



miroen
06-30-2005, 09:05 AM
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

jscheuer1
06-30-2005, 09:27 AM
<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).

miroen
06-30-2005, 02:03 PM
Thanks John,

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

Miroen

miroen
07-29-2005, 11:58 AM
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? :confused:

jscheuer1
07-29-2005, 01:39 PM
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.