Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    43
    Thanks
    7
    Thanked 0 Times in 0 Posts

    How to auto select remote image after automatic file browsing ?

    I'm attempting to assign an image after automatically opening a file, browse window. Here's the code (it simply just clicks the browse button).

    Code:
    <script type="application/javascript">
    document.getElementById('photo').addEventListener('click',function(evt){
                    evt.preventDefault();
        document.getElementById('photo').click();
    });
    
    </script>
    
    <form id="form">
        <input type="file" name="photo" id="photo" value=""/>
        <button id="upload">Browse</button>
    </form>
    With the above code I can automatically prompt the file browse window. How can I take that one step further and assign the value to a remote URL image?

  • #2
    New Coder
    Join Date
    Jul 2008
    Posts
    43
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Over 1700 views and not one comment?

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,087
    Thanks
    23
    Thanked 593 Times in 592 Posts
    Maybe we don't understand the question.

    <input type="file" will generate it's own browse button. Why did you make a second one? And it looks like your waiting for a click event to occur on a input tag.

    I can automatically prompt the file browse window.
    Did not see that when I ran the code.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,294
    Thanks
    10
    Thanked 583 Times in 564 Posts
    i think you want to see the chosen image file once selected, which you can do like this:
    Code:
    <html>
    <img />
    
    <form id="form">
        <input type="file" accept="image/*" onchange="document.images[0].src=URL.createObjectURL(this.files[0]);" />
    </form>
    </html>
    Last edited by rnd me; 05-17-2014 at 09:56 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •