Grzesiek PL

I am creating an application which has to submit form, which basically looks like that:

Code Snippet

<form name="fileform" onsubmit="doUpload2();" enctype="multipart/form-data" method="post">

...

<input type="file" size="30" class="Button" name="File0">

...

<INPUT type="submit" name="uploadbtn" value="Upload" class="Button">

...

</form>

Code Snippet


I automatically fill file0 field with SendKeys, and try tu submit form with such code:

Code Snippet

...

HTMLInputElement Input;

Input = (HTMLInputElement)doc.all.item("uploadbtn", 0);
Input.click();


Button is clicked, but i get JavaScript Error. ('undefined' is empty or is not an object)
I also tried to invoke script doUpload2() instead of clicking button but result is the same.

However if i manually click submit button, form is submitted without errors.

Is there something i am missing here

P.S. I use AxWebBrowser in this application



Re: Internet Explorer Web Development Javascript Error while automatically submitting form using MSHTML

unique_username

I have no idea if the AxWebBrowser control is just like the IE web browser itself, but I know in the web browser world, JavaScript/any OS scripting (e.g. SendKeys) can *NOT* populate, alter, copy, or read the contents of a "file" field type, since it is a security risk.

I would try to manually type the value in the filename box. if this works, then bingo, you have your answer, it can't be done. If it doesn't, then likely your code has issues elsewhere. e.g. I'm not sure if your code snippet is exactly what you have, but 'doc' should be 'document', using 'all' is extremely bad practice, use the DOM instead (if supported).

Otherwise, good luck.




Re: Internet Explorer Web Development Javascript Error while automatically submitting form using MSHTML

Grzesiek PL

Thanks, for the anwser. I did a test, i fill input type "file" with these code:

Code Snippet

HTMLInputFileElement InputFile;

InputFile = (HTMLInputFileElement)doc.all.item((String)H["HtmlName"], 0);
InputFile.focus();
String x = GetValue(H["Value"]);
System.Windows.Forms.SendKeys.SendWait(x);


It works, field is filled and then i manually clicked submit button and form is submitted with NO errors.

If i add code to automatically submit form e.g.

Code Snippet

HTMLInputElement Input;

Input = (HTMLInputElement)doc.all.item((String)H["HtmlName"], 0);
Input.click();


I get JavaScript error, so it must be problem with these button, but i have no idea what it is

P.S. Code for "doc" is
Code Snippet

HTMLDocument doc = new HTMLDocumentClass();
doc = (HTMLDocument)axwb.Document;

where axwb is AxWebBrowser