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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:34:00+00:00 2026-06-12T19:34:00+00:00

continuing from here … since the problem has signifally altered (in my opinion) here

  • 0

continuing from here … since the problem has signifally altered (in my opinion)

here is my code

        for (var i = 0; i < len; i++) {
            (function () {
                var queryid = results.rows.item(i).id; //sql primary key
                var divid = "#" + queryid; //assigned id to divs
                var pressTimer;
                $(divid).mouseup(function(){ //func to handle tap + hold
                clearTimeout(pressTimer)
                // Clear timeout
                return false;
                }).mousedown(function(){
                // Set timeout
                pressTimer = window.setTimeout(function() {
                alert(divid);
                $(".somediv").show();
                $("#anotherdiv").hide();
                $("#button").on("click", function(){
                    var db = window.openDatabase("mydb", "1.0", "mydb", 200000);
                    db.transaction(editrow);    
                    function editrow(tx){
                        var value1 = $("#inputbox1").val();
                        var value2 = $("#inputbox2").val();
                        tx.executeSql("UPDATE mydb SET column1 = " + value1 + ", column2 = " + value2 + " WHERE id = " + queryid);
                        alert(divid); ********
                        successCB();} //query function
                })
                },1000)
                return false; 
                });
                })();
            }   

if i click on the div and i edit the values, they are submitted successfully…
however, if after that i select another div to update its fields, then the new value is updated both to selected div, as well as to the previous selected div..

for instance i select div1 and update the values everything is ok

if after that i select div2 then both div1 and div2 values are update with more recent values for div2

  • 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-12T19:34:01+00:00Added an answer on June 12, 2026 at 7:34 pm

    You are binding the events more than once. In every mousedown on the div, you are binding a click event to the button. You are not asigning the event handler when you call “on” or “click” in jquery, you are adding a handler.

    I didn’t understand if you need the call to setTimeout.

    Try this aproach insted:

    var lastClickedId = null;
    function editrow(tx) {
        var value1 = $("#inputbox1").val();
        var value2 = $("#inputbox2").val();
        var queryid = lastClickedId;
        tx.executeSql("UPDATE mydb SET column1 = " + value1 + ", column2 = " + value2 + " WHERE id = " + queryid);
        alert(queryid);
        lastClickedId = null;
    
        successCB();
    } //query function
    
    $("#button").on("click", function(){
    
        if(lastClickedId != null)
        {
            var db = window.openDatabase("mydb", "1.0", "mydb", 200000);
            db.transaction(editrow);
        }
    });
    
    for (var i = 0; i < len; i++) {
    
        (function () {
            var queryid = results.rows.item(i).id; //sql primary key
            var divid = "#" + queryid; //assigned id to divs
    
            $(divid).click(function(){
                lastClickedId = queryid;
            });
        })();
    }
    

    UPDATE:

    When you bind elements in jquery using bind(func), on(func), click(func), etc, you are registering the function func to be called whenever the event ocurrs. You can register any number of functions. So, for example, if you do:

    $("#div1").on("click", function() { alert("hello"); });
    $("#div1").on("click", function() { alert("world"); });
    

    It will display two alerts when you click. This is because of the way jquery manages events. It calls every function you passed in the event.

    To detach all the clicks events you atached to that element (or elements) with on, just do:

    $("#div1").off("click");
    

    In “pure” javascript you can do this:

    var div1 = document.getElementById("div1");
    
    div1.onclick = function() { alert("hello"); };
    div1.onclick = function() { alert("world"); };
    

    And in this second example, only one alert will be called, because you are directly asigning a value to the function onclick.
    And to remove the event:

    div1.onclick = null;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing a continuing problem distinguishing delegation, composition and aggregation from each other,
Continuing on from this question here: Forum data in mysql database What would be
Plone n00b here, continuing migration issues from 2.5 to 3.3.5. To eliminate any potential
Continuing from the question that I asked here: C++ multi-dimensional data handling In my
Continuing to the post of reading-from-XML-and-storing-the-values-in-database-using-grails am facing an another problem in it. As
Continuing from this question : When I am trying to do fopen on Windows,
I am continuing on from a previous question relating to loading instances of plugins
I've got Python code with a preamble containing the line: from numpy import array,arccosh,random_integers
Continuing from a previous question , I keep searching for the optimal way to
Continuing a previous question I asked here , I now need to move to

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.