0

I have a small script in perl. Within the script there is a 'form'. Heres what the form looks like:

sub print_form {
        my ($tt, $idnum) = @_;
        print "<CENTER>\n";
        print "<FORM METHOD='POST' ACTION='/cgi/thisscript.pl'>\n";
        print " <INPUT type='hidden' name='idnum' value='$idnum' />\n";
        print " <INPUT type='hidden' name='rain' value='$ttprefix' />\n";
        print " <LABEL FOR='pin'>label 1</LABEL>\n";
        print " <SELECT name='pin'>\n";
        my $profiles = $tt->get_profile_urls;
        for my $pin (keys %$profiles){
                print "         <OPTION value='$pin'>$profiles->{$pin}{name} ($pin)</OPTION>\n";
        }
        print " </SELECT>\n";
        print " <BR />\n";
        print " <LABEL FOR='invid'>Select the qouta</LABEL>\n";
        print " <SELECT name='invid'>\n";
        my $qouta = $tt->get_qouta;
        for my $invid (sort { $a <=> $b } keys %$qouta){
                my ($name, $pren) = ($qouta->{$invid}{name}, $qouta->{$invid}{pren});
                print "         <OPTION value='$invid'>$name ($pren)</OPTION>\n";
        }
        print " </SELECT>\n";
        print " <BR />\n";
        print " <LABEL FOR='qty'>qouta quantity</LABEL>\n";
        print " <INPUT type='text' name='qty' value='$atom' />\n";
        print " <BR />\n";
        print " <INPUT type='submit' value='submit'/>\n";
        print "</FORM>\n";
        print "</CENTER>\n";
}

Im trying to loop it so that for example a javascript function (on the same page) would automatically click the 'submit' button # of times.
Is it possible to have javascript 'automatically' click on the submit function? I understand this is possible in Userscripts with grease monkey although I'd like to be able to do this all on the webpage.

3
  • @ds1 has an answer that will submit just fine. Not sure how the loop is supposed to work since the page will be lost on submission. Perhaps google "javascript ajax" and see if that's the sort of thing you're trying to do? Commented Oct 20, 2013 at 7:53
  • @Richard Huxton Page is not lost on submission - the submit occurs on the same page. (Don't think about it like a register/login form) Commented Oct 20, 2013 at 14:39
  • Eh? By definition the submit posts the data to the server which returns a response. The original page (with any javascript variables like a count) will be lost. You either track the count server-side or don't post the page (ajax). Commented Oct 20, 2013 at 15:57

1 Answer 1

1

You're trying to loop what?

In your code there's only one submit Button, in JavaScript you could submit the form like this at any time the form is available (i.e. events like onload):

document.forms[0].submit();

If you want to click the form submit multiple times (for whatever reason), do that submit in a loop (is that what you want to loop) for the amount of submits you want. Although it seems like a bad choice to do so. Alternatively you could also give that submit button an id and simulate a click with JS:

document.getElementById("submit_id").click();
Sign up to request clarification or add additional context in comments.

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.