-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdropdown list from sql tables.html
More file actions
54 lines (44 loc) · 2.29 KB
/
dropdown list from sql tables.html
File metadata and controls
54 lines (44 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Am trying to get data from an sqlite database table to feed to my dropdown menu list. See my thinking below. The problem is I don’t know how to marry the JS function with the HTML part.
HTML.html
Expand|Select|Wrap|Line Numbers
<label for="name"><b>Activity Name:/b></label>
<select name="activity" id="activity" required>
<option value="">--Select--</option>
getActivity()
</select>
JS.js
Expand|Select|Wrap|Line Numbers
function getActivity(tx) {
tx.executeSql('SELECT * FROM tblactivity', [], queryActivity, errorHandler);
function queryActivity(tx, results) {
var len = results.rows.length;
for (var i = 0; i < len; i++) {
var SelectActivity +='<option value="' + results.rows.item(i).activityID +'">'+ results.rows.item(i).ActivityName +'</Option>';
}
//SelectActivity +="</Option";
document.getElementById("activity").innerHTML =SelectActivity;
}}
Alternatively on HTML.html, incorporating the Function like
Expand|Select|Wrap|Line Numbers
<label for="name"><b>Activity Name:/b></label>
<select name="activity" id="activity" required>
<script>
function getActivity(tx) {
tx.executeSql('SELECT * FROM tblactivity', [], queryActivity, errorHandler);
function queryActivity(tx, results) {
var len = results.rows.length;
for (var i = 0; i < len; i++) {
var SelectActivity +='<option value="' + results.rows.item(i).activityID +'">'+ results.rows.item(i).ActivityName +'</Option>';
}
//SelectActivity +="</Option";
document.getElementById("activity").innerHTML =SelectActivity;
}}
</script>
</select>
Apr 7 '18 #1
Subscribe Post Reply
1 5055
gits
gits
5,390 Expert Mod 4TB
basicly you may use both variants - but you would need to call your function - given it does what you want it to do - in the onload-event of your page. by using this event you make sure the DOM is already processed and you can safly use getElementById to get a reference to your select-element.