Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
Is it possible to get a variable or localStorage value to insert in a Web SQL code?

I've created just a simple code to simulate a virtual store with HTML, Web SQL & Javascript language and my question is: Is it possible to get a variable or localStorage value to insert in a Web SQL code?

I just need to change the code number "100013" below by a variable or localStorage item.

var bdd = openDatabase("bdLojaVirtual", "2.0", "LojaVirtual", 2000000);
var mostrar;

var button = document.getElementById("pesquisar");
button.onclick = function consultarProduto() {
    var produto = document.getElementById("codigo").value;
    produto = produto;
    localStorage.setItem("Item selecionado", produto);
}

bdd.transaction(function (selecionar) {
    var produto = localStorage.getItem("Item selecionado");
    selecionar.executeSql ('SELECT nome FROM produto WHERE codigo = 100013', [], 
    function (selecionar, results) {
    var len = results.rows.length, i;
       for (i = 0; i < len; i++) {
           mostrar = "<p><b>" + results.rows.item(i).nome + "</b></p>";
           document.querySelector('#aqui').innerHTML += mostrar;
       }
     }, null);
 });

The whole project is at https://github.com/jmlJunior/portifolioPessoal

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After some research I got it: I've just replaced the code number "100013" by "?" and "[]" by "[produto]" and it works well.

bdd.transaction(function (selecionar) {
var produto = localStorage.getItem("Item selecionado");
selecionar.executeSql ('SELECT nome FROM produto WHERE codigo = ?', [produto], 
function (selecionar, results) {
var len = results.rows.length, i;
   for (i = 0; i < len; i++) {
       mostrar = "<p><b>" + results.rows.item(i).nome + "</b></p>";
       document.querySelector('#aqui').innerHTML += mostrar;
       }
    }, null);
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!