Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DHTML and file upload element

Status
Not open for further replies.

Greggie

Technical User
Jun 25, 2001
24
0
0
AU
I am writing a program which takes info from a client side database and fills in a PHP form. There is no problem with most of the common text input elements. However, one of the elements is a file upload input type.
My program simply rewrites the code of the webpage to add the appropriate value to the text input element however, this doesn't work for the file upload input (where I want to upload a jpeg from the user side's PC to the web site). It seems that the the file upload element is designed such that the user must explicitly nominate the file to be uploaded (I guess in order to protect the privacy of the user). To get around this, I am using SendKeys to fill out the file upload element with the appropriate file name which works most of the time. But I really don't like SendKeys as I find it erratic and I am looking for another way to program the value of the file upload input element.
I tried an experiment using DHTML with a Command Button that sets the value of the input elements and this works fine for the text inputs but still not for the file upload element
e.g. PhotoFileUpload.value = "C:\MyPictures\Bart.jpeg"

The code doesn't cause an error, but the browser fails to recognise the value until it is typed in by the user.
Does anyone know if it is possible to program the value of the file upload web page input element without user intervention or without using SendKeys?
 

Are you using the webbrowser control? If so then ...
[tt]
Dim InputElements As Object, Dim InputElement As Object
Set InputElements = WB.Document.All.Tags("input")
For Each InputElement In InputElements
If UCase(InputElement.Name) = UCase(InputFieldName) Then
InputElement.Value = ValueToBeEntered
Exit For
End If
Next
[/tt]

Good Luck

 
Thanks very much for your response. The suggested solution doesn't actually work for the file type input element but the code you gave me is a much better solution for filling out the the other input elements on the web page. Previously I was getting the code for the web page and inserting the values by rewriting the page using string processing then reloading it into the webbrowser. Your code is much more straightforward.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top