...

View Full Version : fixed number of multiple submits to a page needed



skydiverMN
10-21-2008, 05:40 AM
I'm trying to submit a page multiple times, something like 4 times/sec for only a second or two. I know this isn't the typical use for js, but it's for an online game that uses AJAX and allows multiple clicks before a final 'summary' of events comes back.

Below works fine and fires the submit action until the end of time. What I'd like to do is only submit the page, let's say, 4 times. I thought about using a hidden field, but when I submit the page all values are lost/reset. Would using cookies be the only way? If so, can you include some code for this? Thanks for your help!



<HTML>
<head>
<SCRIPT LANGUAGE="JAVASCRIPT">
var t=0;
function load()
{
t = setInterval("submitme()", 450);
}

function submitme()
{
document.forms[0].submit();
}

</SCRIPT>
</head>

<body onLoad="load()">
Current Iteration: <span id="curIteration">0</span><br><br>

<form>
form stuff
</form>

</BODY>
</HTML>

rnd me
10-21-2008, 08:26 AM
use ajax to submit, not forms.

if you must use forms, add a hidden iframe to the page, give it a name and change the target attrib of your form to that name.

skydiverMN
10-21-2008, 03:40 PM
Thanks for the post, but I do have a question about it...

I'm just creating my html files on the fly so I'm trying to make them as simplistic as possible. The only AJAX I write is using vb.net or c# within visual studio and I'm not going to try writing it in a text editor. Within my application I have a webbrowser control and it simply navigates to the dynamic html page and does the submits (well, at least in theory...).

Regarding your use of iFrame:
I have a 'parent' page that'll contain the 'child' auto-submitting page, at least, that's how I understand it'll work. The problem exists as to how I'll access a counter value (i.e. textbox value). The 'child' auto-submitting page can't do a getElementByID from the parent and I don't think the parent can determine when a postback by the child occurs. Pickin' up what I'm putting down? Thoughts?

Please explain how you think I might be able to solve my issue.
Thanks.

skydiverMN
10-21-2008, 04:33 PM
I was able to figure out how to only post X number of times and then stop. It required 2 pages, one as a parent to contain an iFrame, and a child, that will reside in the iframe and actually do the posting. The child updates a textbox on the parent with the current iteration. It'll stop when the correct number is reached and clear the timer function.

Parent:


<HTML>
<BODY>
<form id="formsubmit">
<input type="text" id="postCounter" value="0";>
<iframe name="iFrame1" src="bounty.html" width="50%" align="left">
</form>
</iframe>
</BODY>
</HTML>


Child:


<HTML>
<head>
<SCRIPT type="text/javascript">
var t=0;
var i=0;
function load()
{
t = setInterval("submitme();", 250);
}

function submitme()
{
var ctl;
ctl=parent.document.forms[0].postCounter;
i = parseInt(ctl.value);
i=i+1;
ctl.value = i;
//document.forms[0].getElementByID("x").innerHTML = i;
if (parseInt(i)<6)
{
// alert("Value: " + i);
document.forms[0].submit();
}
else
{
clearInterval(t);
// alert("DONE!");
}
}
</SCRIPT>
</head>
<body onLoad="load();">
<form>
PUT WHATEVER NEEDS TO GET POSTED HERE
</form>
</BODY>
</HTML>


Thanks for your insight and help! :thumbsup:

SkydiverMN



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum