Link to home
Start Free TrialLog in
Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

asked on

populating datalist

Hi! Experts, how to make this code that the data from Web Sql will populate to datalist? below is the code. Please help!

    function showme()
    {
        db.transaction(function (tx)
    {
    tx.executeSql('SELECT * FROM iTable2', [], function (tx, results) {
    var len = results.rows.length, i;
    msg = "<p>Found rows: " + len + "</p>";
    document.querySelector('#status').innerHTML +=  msg;
    for (i = 0; i < len; i++){
    msg = "<p><b>" + results.rows.item(i).firstName + "</b></p>";
    document.querySelector('#status').innerHTML +=  msg;
        }
       
        }, null);
    });
    }

this is my datalist

<lable>Student names:</lable>
<input type="text" list="names" />
   
<datalist id="names">
    <option value="">
    <option value="">
</datalist>
Avatar of SSupreme
SSupreme
Flag of Belarus image

Could you provide example of output you get and how the end result should look like, please.
Avatar of Rob
You should be aware that WebSQL is no longer supported.  I can show you how to populate a datalist though if you still want to go down that track? Unless of course you are using the IndexedDB ? http://www.w3.org/TR/IndexedDB/
Avatar of Whing Dela Cruz

ASKER

Hi Rob lurd, I'm still interested to do it. Please provide example. Thanks!
Excluding SQL side of things, here is how you can populate a datalist with an array:  http://jsbin.com/didabiheci/1/edit?html,js,output

Note: I've used jQuery to simplify things and make the code cross browser compatible

$(function() {
  var names = ['Rob', 'John','Andrew','Jason','Steven'];
  for (i=0; i<names.length; i++) {
    $("#names").append("<option value='"+names[i]+"'/>");
  }
});

Open in new window

Rob lurd, Please tell me how its possible that base on my post coded above, the data is coming from the database (Web Sql). Could you provide solution  for this. Please understand that I am a beginner for HTML5. Thanks!
Please understand that I am a beginner for HTML5
given that's the case, WHY are you using web SQL?
Please understand that I'm not trying to be difficult but rather steer you away from technologies that are not in use.  A database IMO has no place in this context within the browser.  It exposes your data and I would never use it.  Your data should be stored on your server and let it do the processing.  I know that spreading the processing of certain queries would reduce the load on a server but it may impact greatly on the client when it doesn't need to and may give unexpected results that you have no control over.
Just to accomplish what I started. Could you tell me Rob where should I start? If not Web Sql, What should be?
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot Rob, this is actually part of my practice. Thanks for your great suggestions...
No problem but did you mean to grade it a B? If not can you request it to be changed