Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass this parameter to this function?
    text
    copied!<p>Here is my function:</p> <pre><code> function updateRecord(id, textEl) { db.transaction(function(tx) { tx.executeSql("UPDATE products SET product = ? WHERE id = ?", [textEl.innerHTML, id], null, onError); }); } </code></pre> <p>Here is the call:</p> <pre><code>&lt;span contenteditable="true" onkeyup="updateRecord('+item['id']+', this)"&gt;'+ item['product'] + '&lt;/span&gt; </code></pre> <p>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:</p> <pre><code>&lt;span contenteditable="true" onkeyup="updateRecord('+item['id']+', "product", this)"&gt;'+ item['product'] + '&lt;/span&gt; function updateRecord(id, column, textEl) { db.transaction(function(tx) { tx.executeSql("UPDATE products SET " + column + " = ? WHERE id = ?", [textEl.innerHTML, id], null, onError); }); } </code></pre> <p>They should do the exact same thing, I only specified the <em>product</em> column in the call instead of in the function. Is my syntax incorrect, am I missing something?</p> <p>Edit: Here is the full function in which the call is located:</p> <pre><code> // 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 &lt; result.rows.length; i++) { item = result.rows.item(i); document.getElementById('results').innerHTML += '&lt;li&gt;&lt;span contenteditable="true" onkeyup="updateRecord('+item['id']+', "product", this)"&gt;'+ item['product'] + '&lt;/span&gt; &lt;a href="#" onclick="deleteRecord('+item['id']+')"&gt;x&lt;/a&gt;&lt;/li&gt;'; } }); }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload