3

I have no experience with web programming, so my question would be a very simple one. I want to download a lot of files by filling out forms in a web page. The web page's extension is .aspx, and I am interested in only one field and a button. By fooling around with the console in my browser, I figured out that executing:

document.getElementById('TxtRegNo').value = 'blahblah`;

will fill the concerned field. Also doing a

__doPostBack("ImageButton1","Click");

will download the .pdf file curresponding to blahblah. The actual value which needs to be entered is a sequence like PAG-1200 to PAG-1900. I tried using a for loop, like this:

for (var i = 21618; i < 21621; i++) 
{
document.getElementById('TxtRegNo').value = 'B14-' + i;
__doPostBack("ImageButton1","Click");
}

but it doesnot work as expected. only the last document gets downloaded, and I get this in the console:

enter image description here

Thought this error does not come whe nI run in FireFox's console, I can still run only one file. Could anyone tell me how to do this?

Community
  • 1
  • 1
daltonfury42
  • 3,103
  • 2
  • 30
  • 47

1 Answers1

0

Try this:

  1. Inject jQuery to the page via the console, as explained here: Include jQuery in the JavaScript Console
  2. In your for loop clone the form, set the values as you wish and submit the form jQuery('form').clone().find('#TxtRegNo').val('blah').parent('form').submit();

If the page contains more than one form, you should specify it. 'form' works like css selectors here. This will find all forms on the page. Just use '#elementId' or '.elementsClassName' to be more concrete, if necessary.

Maybe you also need to change the name of the form (to be able to submit the forms simulatiously). I didn't try it, this is just a guess.

If you want to split the code to several lines you can also do this:

var myFormClone = jQuery('form').clone();
myFormClone.find('#TxtRegNo').val('blah');
myFormClone.attr('name', 'uniquename_' + iterationVariableOfForLoop);
myFormClone.submit();

If the submit failes, try:

myFormClone.get(0).submit();

Good luck!

Community
  • 1
  • 1
Armin
  • 15,582
  • 10
  • 47
  • 64
  • When I type `var jq = document.createElement('script');`, it says `undefined` – daltonfury42 Jul 09 '15 at 13:38
  • I think this is normal, because this line of code is not returning anything. It is assigning the created script to the variable. Do a `jQuery()` console first, and you get undefined. Then execute all lines of the other answer and try again :) – Armin Jul 09 '15 at 16:58
  • Am I supposed to execute all the lines in the other answer as it is? – daltonfury42 Jul 09 '15 at 17:01
  • Yes! But the last one (`jQuery.noConflict()`) needs to be a little bit delayed. Because jQuery needs to be loaded, first. But then the whole magic of jQuery is available :) And if the page contains no other JavaScript framework using `$`, the conflict mode is unnecessary. – Armin Jul 09 '15 at 17:02
  • This is what I get, no download, http://picresize.com/popup.html?images/rsz_screenshot_from_2015-07-09_223521.png – daltonfury42 Jul 09 '15 at 17:08