Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up fixed number of multiple submits to a page needed

    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!

    Code:
    <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>

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    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.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #3
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    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.

  • #4
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I figgurd it out!

    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:
    Code:
    <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:
    Code:
    <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!

    SkydiverMN


  •  

    Tags for this Thread

    Posting Permissions

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