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 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2013
    Posts
    20
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Question How do I wrap html form tags in javascript while loop?

    how do I wrap html form tags in a javascript while loop? Below example isn't working. do I have to do special wrapping when wrapping like the echo in php? If so how? I learn from examples. Basically want this to auto-submit 5 times to my dummy form.


    Code:
    <body>
    <SCRIPT LANGUAGE="Javascript">
    while(i<5){
     
    <form action="http://someweb.com"  method="post" name="form_confirm" id="form_confirm">
    <input class="post" type="text" id="username_reg" name="username" value="somethingname" size="25" maxlength="25" />
    <input class="post" type="password" name="password_confirm" value="somethingpass" size="25" maxlength="25" />
    <input class="mainoption" type="submit" name="submit" id="submit" value="Save">
    </form>
    
    document.getElementById("form_confirm").submit();
    
    i++
    }
    
    </script>
    </body>

  • #2
    New Coder
    Join Date
    May 2005
    Location
    New Zealand
    Posts
    76
    Thanks
    0
    Thanked 6 Times in 6 Posts
    What you are trying will not work like that.

    The first issue is that the form is not added to the document anywhere so the document.getElementById() will fail, second even if you did add the form to the DOM submitting it would submit the page to the form's action url so no further loops would execute.

    Have a look at jQuery's post() method to post a form using AJAX. http://api.jquery.com/jQuery.post/

    So using that the code to do what you want would probably be...

    Code:
    for(var i = 0; i < 5; i++)
    {
       $.post("http://someweb.com", { username: "Something", password_confirm: "Somthingpass" } );
    }


  •  

    Posting Permissions

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