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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:25:35+00:00 2026-05-20T03:25:35+00:00

Here is my function: function updateRecord(id, textEl) { db.transaction(function(tx) { tx.executeSql(UPDATE products SET product

  • 0

Here is my function:

  function updateRecord(id, textEl) {
    db.transaction(function(tx) {
      tx.executeSql("UPDATE products SET product = ? WHERE id = ?", [textEl.innerHTML, id], null, onError);
    });
  }

Here is the call:

<span contenteditable="true" onkeyup="updateRecord('+item['id']+', this)">'+
        item['product'] + '</span>

I would like to add a parameter to the call so that I can use the function for multiple columns. Here is what I’m trying but it doesn’t work:

<span contenteditable="true" onkeyup="updateRecord('+item['id']+', "product", this)">'+
        item['product'] + '</span>

  function updateRecord(id, column, textEl) {
    db.transaction(function(tx) {
      tx.executeSql("UPDATE products SET " + column + " = ? WHERE id = ?", [textEl.innerHTML, id], null, onError);
    });
  }

They should do the exact same thing, I only specified the product column in the call instead of in the function. Is my syntax incorrect, am I missing something?

Edit:
Here is the full function in which the call is located:

  // select all records and display them
  function showRecords() {
    document.getElementById('results').innerHTML = '';
    db.transaction(function(tx) {
      tx.executeSql("SELECT * FROM products", [], function(tx, result) {
        for (var i = 0, item = null; i < result.rows.length; i++) {
          item = result.rows.item(i);
          document.getElementById('results').innerHTML += 
              '<li><span contenteditable="true" onkeyup="updateRecord('+item['id']+', "product", this)">'+
        item['product'] + '</span> <a href="#" onclick="deleteRecord('+item['id']+')">x</a></li>';
        }
      });
    });
  }
  • 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-20T03:25:35+00:00Added an answer on May 20, 2026 at 3:25 am

    Update: Ok, then the issue only lies in using double quotes for product. Use single quotes and escape them:

    document.getElementById('results').innerHTML += 
              '<li><span contenteditable="true" onkeyup="updateRecord('+item['id']+', \'product\', this)">' + ...;
    

    But you really should consider to refactor your code. E.g. you could write it like this:

    var results = document.getElementById('results');
    var container = document.createDocumentFragment();
    for (var i = 0, l = result.rows.length; i < l; i++) {
        var item = result.rows.item(i);
        var li = document.createElement('li');
    
        var span = document.createElement('span');
        span.setAttribute('contenteditable', 'true');
        span.onkeyup = (function(item) {
                return function() {
                    updateRecord(item['id'], 'product', this);
                }
        }(item));
        span.innerHTML = item['product'];
    
        var a = document.createElement('a');
        a.href = '#';
        a.onclick = (function(item) {
                return function() {
                    deleteRecord(item['id'])
                }
        }(item));
        a.innerHTML = 'x';
    
        li.appendChild(span);
        li.appendChild(a);
        container.appendChild(li);
    }
    results.appendChild(container);
    

    It is more code but easier to maintain in the long run…


    You have syntax and quotation issues. This should work:

    onkeyup="updateRecord('item[\'id\']', 'product', this)"
    

    But the code seems a bit weird to me. Is this in your actual HTML or are you echoing or printing it? Because

    <span...>'+ item['product'] + '</span>
    

    looks weird in HTML. It will literally put '+ item['product'] + ' inside the <span> tag. Please post a more complete version of your code.

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

Sidebar

Related Questions

No related questions found

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.