0

I've been trying really hard on this but to no win.

I have a button and a div. When user clicks that button the file browser opens up and allows user to choose image. The image gets added to the div. That's the front image.

I've got the code for that. But I also wanted to duplicate the controls so that the user can add back image. But that doesn't seem to work. Help me fix the code

OR

If you guys can suggest some better alternative then it would be amazing.

Here's the jsbin demo:

http://jsbin.com/pulug/1/

HTML:::

    <html>
    <head>
        <script src="http://code.jquery.com/jquery-latest.js"></script>
    </head>
    <body>
        <fieldset>
            <legend>Choose Front Image</legend>
            <input type=file id='file' class="button" onchange="startRead()"/>
            <div id="dragherefront" >Drop files here</div>  
            <div id="manualfront"></div>
        </fieldset>
        <fieldset>
            <legend>Choose Back Image</legend>
            <input type=file id='file' class="button" onchange="startRead()"/>
            <div id="draghereback" >Drop files here</div>  
            <div id="manualback"></div>
        </fieldset>
    </body>
    </html>

CSS::

 #dragherefront{
     width: 128px;
     height: 128px;
     background-color: rgba(221,214,155,0.4);
     border: 1px dashed black;
     text-align: center;
     position: absolute;
     opacity: 0;
     overflow: hidden;
 }

 #draghereback{
     width: 28px;
     height: 128px;
     background-color: rgba(221,214,155,0.4);
     border: 1px dashed black;
     text-align: center;
     position: absolute;
     opacity: 0;
     overflow: hidden;
 }

 #manualfront{
     width: 128px;
     height: 128px;
     overflow: hidden
     background-color: rgba(221,214,221,0.3);
     border: 1px dashed black;
     overflow: hidden;
     z-index: 0;
 }

 #manualback{
     width: 128px;
     height: 128px;
     overflow: hidden
     background-color: rgba(221,214,221,0.3);
     border: 1px dashed black;
     overflow: hidden;
     z-index: 0;
 }
6
  • 1
    please narrow your issues down to specific areas of your code and provide that code in your question Commented Jun 27, 2014 at 21:17
  • 2
    "Help me fix the code" No. At least not until you've shown a conscious attempt to fix it yourself, included relevant code in your question, and added far far more detail as to what the code should be doing Commented Jun 27, 2014 at 21:17
  • I've provided the jsbin demo but anyways i'm giving the code. Commented Jun 27, 2014 at 21:18
  • I tried to replicate by changing IDs and altering the code but in vain. Commented Jun 27, 2014 at 21:25
  • As others have mentioned, it would be helpful to see what you tried and what went wrong. Commented Jun 27, 2014 at 21:27

1 Answer 1

2

Both inputs have the same ID file. You cant copy the code 1:1, you need to change the IDs (for example set it in the first code snipet to file1 and in the second to file2). The same with the divs. And you have to rewrite the code a bit so that it works with multible fields.

Sign up to request clarification or add additional context in comments.

1 Comment

@user3716080 You don't understand the JS-code you have there, do you? Don't understand me wrong, but as I said, you cant just copy past the HTML, and change the IDs, you also need some work on the JS-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.