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 8935985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:06:47+00:00 2026-06-15T10:06:47+00:00

I had some question that I not sure how actually to solve it, basically

  • 0

I had some question that I not sure how actually to solve it, basically I will draw out a data and append into the web, and assign each data with it owns div button, which are remove and update, each click will remove all and reappend the data, code are as below

function DrawData(){ var txtHd = $('input[id$="hidText1"]').val(); 
if (typeof(txtHd) != "undefined" || txtHd != "") //if have value
{ 
    var sSplit = txtHd.split(sDelimiter);
    var i;
    var div1, div2, div3, div4, div5, row1, comment;
    for (i=0;i<=sSplit.length-1;i++){
        if (sSplit[i].trim() == "") { return true; }
        comment = "";
        iAdd1 = i + 1;
        div1 = "<div class=container><div id=" + sSplit[i] +" class=number>" + iAdd1 + "</div>";
        div2 = "<div class=stage>Level " + iAdd1 + "</div>";
        div3 = "<div class=name>" + sSplit[i] + "</div>";
        div4 = "<div id=rem" + iAdd1 +" class=rem>remove</div>";
        div5 = "<div id=upd" + iAdd1 +" class=upd>update</div>";;
        div6 = "<div class=drfm>Comment: " + comment +  "</div></div>";

        row1 = div1 + div2 + div3 + div4 + div5 + div6;
        $('#dtdr').append(row1);
        $('#errmsg').fadeOut();
        removeValue(); //add remove function
        updateValue(); //add update function into the div
    }
}}

function updateValue(){
$('.upd').on('click', function(){ 
    var cLb=$('input[id$="hidText1"]').val();
    var updName = $(this).parent().find('.name').text();
    var repName = $('input[id$=fl_Approval]').val().trim();

    if (repName == ""){ $('#errmsg').text("Add error: [ Not allow to add empty name ]"); $('#errmsg').fadeIn(); return; } //check empty value
    if (checkArrayDup(repName,cLb) == true){ $('#errmsg').text("Add error: [ Name: "+ repName + " exist in the list ]"); $('#errmsg').fadeIn(); return; } //check duplicate

    updName = updName + sDelimiter;
    repName = repName + sDelimiter;
    var newVal= $('input[id$="hidText1"]').val().replace(updName ,repName);
    $('input[id$="hidText1"]').val(newVal);
    $('.container').remove();
    DrawData();
});

it work fine, but the problem now is, the code are not efficient, and I don’t have any idea on how to fix this, the for loop had create multiple click handler at the update button, so whenever I click the button, like it say, I had 5 data on it, the first data will fire 5 times of click event, and second data will fire 4 times of click event, these will go on until last data and cause the checking on duplicate data not working properly, any idea on how to fix this? Sorry for my poor English, any help will be great

  • 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-15T10:06:48+00:00Added an answer on June 15, 2026 at 10:06 am

    Would using event delegation work for you? Instead of assigning event handlers right on the .upd div, you could do something like:

    $('#dtdr').on('click', '.upd', function(e) { console.log(this); # --> .upd div });
    

    This will delegate the click event to the #dtdr div, which should already exist. When someone clicks the div it will check if the click originated from the .upd div and execute the function. This way, you never have to assign new event handlers when rows are added.

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

Sidebar

Related Questions

Here is a question that I have had for some time but never actually
Not sure that i had structured the question right ,as i am not sure
EDIT: I'm not sure that my original question is clear enough. I need an
I'm sure this is an complete Noob question... but I've actually never had to
I am new to Android services so I had some questions that would clarify
This question has two parts. Part 1. Yesterday I had some code which would
I had a question regarding this matter some days ago, but I'm still wondering
I had this working at some point, as I had a question about this
I've had a test, and there was a question I lost some points on,
I had some code that constructed an object: function gridObjConst(id, itemName, itemPrice, itemListPrice, width,

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.