Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6321843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:13:21+00:00 2026-05-24T16:13:21+00:00

I have followed the following link and implemented the example for my own script.

  • 0

I have followed the following link and implemented the example for my own script.

Preview an image before it is uploaded

I have 8 file upload inputs followed by a img tag of it’s own

<input type="file" name="file[]" accept="image/gif,image/jpeg" onchange="readURL(this,1);"/>
<img id="imagediv1" src="#" alt="your image" />

Now the javascript I modified

function readURL(input,cnum) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            var cimage = 'imagediv'+cnum;
            reader.onload = function (e) {
                $("#cimage")
                    .attr('src', e.target.result)
                    .width(150)
                    .height(200);
            };

            reader.readAsDataURL(input.files[0]);
  }     }
}

I did an alert(); within the javascript and the cimage var does get created properly.
However, the img doesn’t change as it does in the example. I did try manually creating a function for each imagediv#, and it works fine.

Am I missing something within the javascript ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:13:22+00:00Added an answer on May 24, 2026 at 4:13 pm

    You need to take “cimage” out of the quotes and instead concatenate it to “#”:

    $("#"+cimage)
    

    Or, better yet, don’t bother with creating the cimage variable at all and just do this:

    $("#imagediv" + cnum)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have project which includes external jar file in it, I followed this link
I am doing the walkthrough in the following link: http://msdn.microsoft.com/en-us/library/zt39148a%28VS.80%29.aspx I have followed it
I have followed the following instructions in setting a git repository locally in one
I have followed Apple's documentation on localizing iPhone software, using the genstrings ruby script
I have followed this article and implemented my service and I can open the
I have gone through following links enter link description here enter link description here
I have followed the following railscast about adding pdfkit to an application, and I
I'm using java 6 annotation processing api. I have followed the following excellent tutorial
I am trying to upload a favicon in my wordpress site. I have followed
I have an xml file which looks like the below example <Ids> <Id> <set>ai</set>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.