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

  • SEARCH
  • Home
  • 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 8881553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:22:16+00:00 2026-06-14T20:22:16+00:00

I am trying to invent hot water :D. I am using html5Uploader and everything

  • 0

I am trying to invent hot water :D. I am using html5Uploader and everything is working fine (images are being uploaded without any error).
Problem comes a bit latter, in this part:

onServerLoad: function(e, file) {
    $('.img_upload').on('click', function() {
        $('#text').val($('#text').val() + $(this).attr('title'));
    });
}

Value is being added to the textarea but it is added number of times as there are uploaded images (for example I have 5 images with name first.png it will add first.png five time to the text area ). How can I avoid this?

$(function() {
    var fileTemplate = "<div id=\"{{id}}\">";
    fileTemplate += "<div class=\"preview\"></div>";
    fileTemplate += "<div class=\"filename\">{{filename}}</div>";
    fileTemplate += "</div>";

    function slugify(text) {
        text = text.replace(/[^-a-zA-Z0-9,&\s]+/ig, '');
        text = text.replace(/-/gi, "_");
        text = text.replace(/\s/gi, "-");
        return text;
    }
    $("#dropbox").html5Uploader({
        onClientLoadStart: function(e, file) {
            var upload = $("#upload");
            if (upload.is(":hidden")) {
                upload.show();
            }
            upload.append(fileTemplate.replace(/{{id}}/g, slugify(file.name)).replace(/{{filename}}/g, file.name));
        },
        onClientLoad: function(e, file) {
            $("#" + slugify(file.name)).find(".preview").append("<img class=img_upload title=\"" + file.name + "\" src=\"" + e.target.result + "\" alt=\"\">");
        },
        onServerLoad: function(e, file) {
            $('.img_upload').on('click', function() {
                $('#text').val($('#text').val() + $(this).attr('title'));
            });
        }
    });
});
  • 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-06-14T20:22:17+00:00Added an answer on June 14, 2026 at 8:22 pm

    One way would be to check to see if it’s already in there, like this:

    var _val = $('#text').val(), title = $(this).attr('title');
    if ( _val.indexOf( title ) === -1 ) {
        // here you add the code
        $('#text').val( _val + title );
    }
    

    But I think the problem may be in the way you’re fetching the name, try using e.target.result or file.name

    var _val = $('#text').val(), name = file.name || e.target.result;
    if ( _val.indexOf( name ) === -1 ) {
        // here you add the code
        $('#text').val( _val + name );
    }
    

    If you want to add the same one a specific number of times, there are a few ways to do that.

    Via for loop:

    // this is if you want to add the duplicates immediately
    var
        // the amount of times you want to create the duplicatation
        NUMBER_OF_TIMES = 10,
        // the current value
        _val = $('#text').val(),
        // the title
        title = $(this).attr('title');
    if ( _val.indexOf( title ) === -1 ) {
        for ( var i = 0; i < NUMBER_OF_TIMES; i ++ )
            $('#text').val( _val + name );
    }
    

    Otherwise, you can check the number of occurrences, and then append if necessary:

    // this is if you want to add the duplicates a certain number of times dynamically
    var
        // the amount of times you want to create the duplicatation
        NUMBER_OF_TIMES = 10,
        // the current value
        _val = $('#text').val(),
        // the title
        title = $(this).attr('title')
        // Returns the number of occurences
        howMany = function(str, substr) {
            var intRet = 0;
    
            // continuously run until the substring isn't found anymore
            while ( str.indexOf(substr) !== -1 ) {
                // get rid of first substring
                str = str.replace(substr, '');
                // add one to the amount of substrings
                intRet++;
            }
    
            // check to see if there are any occurrences, if not, return -1
            return (intRet > 0 ? intRet : -1);
        };
    if ( _val.indexOf( title ) === -1 && howMany(_val, title) <= NUMBER_OF_TIMES ) {
        $('#text').val( _val + name );
    }
    

    I’ve tried making the comments are informative as possible, but if you do not understand a part of it, just comment below. Try it out and tell me how it goes! XD

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to share some text using an intent: Intent i = new Intent(android.content.Intent.ACTION_SEND);
I am trying not to re-invent the wheel, and thus I am looking for
I'm trying to re-invent Preview.app. I've been told that some examples in /Developers/Examples/AppKit will
Yes, I AM trying to re-invent the wheel. :-) . I am doing my
I've been working on building a simple 3d graphic engine and I'm trying to
I am a newbie to Android development. I am trying to invent a broadcast
I am working on some reports and I am trying to create a query
I am trying to create a hot spot on my tablet that acts like
I am trying to traverse a binary tree using twalk() with <search.h> #define _GNU_SOURCE
I'm trying to find default Intent which device is using to support specific mime

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.