0

I am trying to automate a file upload process for a courier we use. I need to upload a CSV file with a form on there website. But it seems I cannot use the DOM to change the input value for a file input.

Is there a way I can do this? I am trying to do it like this;

...Document.getelementbyid("userFile").innertext = filepath

But it doesn't change?

Any idea

2
  • Because inputs don't have innerText or innerHTML, but value. Also, khm, proper capitalisation. Commented Mar 28, 2015 at 21:58
  • a little known-fact: you can leave the file input populated, then every time you call new FileReader().read(), it will grab the current file contents, updates and all. so, if you left your page open, you can run a poll on the input and upload changes when they happen. i made the watchfile lib for this purpose: github.com/rndme/watchfile Commented Mar 28, 2015 at 22:27

1 Answer 1

0

You need to use .value for HTML inputs.

As seen here: Getting value of HTML text input

document.getElementById('email').value;

or

Document.getelementbyid("userFile").value = filepath
Sign up to request clarification or add additional context in comments.

6 Comments

value will not update file input as supposedly its a security thing in browsers. Any ideas how to get round it?
im trying to put a string value to the file into the .value is this right?
@user3348264 Yes it is. Show us your code or check for mistakes by yourself :)
Document.getelementbyid("userFile").Value = filepath
Maybe: 'document.getelementbyid("userFile").value = "filepath";' Does that work (even if it's not what you want to achieve, i guess, because you certainly use filepath as a variable)? I recommend FireBug for FireFox to debug your web code.
|

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.