Whing Dela Cruz
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('#s tatus').in nerHTML += msg;
for (i = 0; i < len; i++){
msg = "<p><b>" + results.rows.item(i).first Name + "</b></p>";
document.querySelector('#s tatus').in nerHTML += msg;
}
}, null);
});
}
this is my datalist
<lable>Student names:</lable>
<input type="text" list="names" />
<datalist id="names">
<option value="">
<option value="">
</datalist>
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('#s
for (i = 0; i < len; i++){
msg = "<p><b>" + results.rows.item(i).first
document.querySelector('#s
}
}, null);
});
}
this is my datalist
<lable>Student names:</lable>
<input type="text" list="names" />
<datalist id="names">
<option value="">
<option value="">
</datalist>
Could you provide example of output you get and how the end result should look like, please.
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/
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
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]+"'/>");
}
});
ASKER
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 HTML5given 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.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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