0

I have this html code:

<form name="input" action="html_form_action.asp" method="post" id="formID">
Username: <input type="text" name="user" />
          <input type="submit" value="Submit" />
</form>

<script>
    for (i=0;i<10;i++) {document.getElementById('formID').submit; }
</script>

I'm trying to submit the same thing several times.
But as you can guess, it always submits once, and refresh the page.

How can I avoid this and submit as many times I want?

3
  • You're going to have to submit the form via XMLHttpRequest. Commented May 19, 2012 at 20:11
  • You should rethink this, submitting forms automatically without user interaction is a bad idea as it may pop up browser warnings. What do you want to achieve? Cheating on a game? Commented May 19, 2012 at 20:11
  • 1
    Convert the submit process into an AJAX request, then you can run that however many zillions of times you want. calling .submit() directly is no different than clicking a submit button yourself. Commented May 19, 2012 at 20:12

4 Answers 4

3

In addition to using Ajax, you could also set the target of the form to "_blank", causing the form to submit to a new window or tab.

<form target="_blank" name="input" action="html_form_action.asp" method="post" id="formID">

The browser can open as many windows as you let it so you could go on for a while.

This would be incredibly annoying to a user though. I hope you know what you're doing.

Sign up to request clarification or add additional context in comments.

Comments

2

Use AJAX to send requests silently to the server (i.e. without a refresh).

or instead of submitting the form 10 times, why not move the loop into your ASP file - your form submits once and something happens 10 times over on the server.

What are you trying to do?

Comments

1

You must submit form by Ajax. use JQuery.Ajax

$(function(){
  $.ajax({
    url:'html_form_action.asp',
    data: $("form").serialize(),
    // other setting
    success: function(){
      // what you do after post
    }
  });
});

visit: http://api.jquery.com/jQuery.ajax/ for other setting

Comments

1

Try this:

$('form[name="formname"]').submit(function(){
    form = $('form[name="formname"]').serialize();  
    url1 = 'http://...';
    url2 = 'http://...';

    $.ajax({
        url:url1,
        type:'POST',
        data:form,
        success:function(result){
            $.ajax({
                url     :url2,
                type    :'POST',
                data    :form,
                success :function(result){
                }
            });
        }
    });
    return false;
});

Replace formname with the name of the form Peplace url1 and url2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.