473,379 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to create Dropdown menu list from sqlite database table

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
  1.  
  2.         <label for="name"><b>Activity Name:/b></label>          
  3.         <select name="activity" id="activity" required>
  4.                         <option value="">--Select--</option>
  5.                         getActivity()
  6.                          </select>

JS.js


Expand|Select|Wrap|Line Numbers
  1.         function getActivity(tx) {
  2.                 tx.executeSql('SELECT * FROM tblactivity', [], queryActivity, errorHandler);
  3.                     function queryActivity(tx, results) {
  4.                 var len = results.rows.length;
  5.                 for (var i = 0; i < len; i++) {
  6.                    var SelectActivity +='<option value="' + results.rows.item(i).activityID +'">'+ results.rows.item(i).ActivityName +'</Option>';
  7.                 }
  8.                 //SelectActivity +="</Option";
  9.                 document.getElementById("activity").innerHTML =SelectActivity;
  10.             }}


Alternatively on HTML.html, incorporating the Function like

Expand|Select|Wrap|Line Numbers
  1.  
  2.         <label for="name"><b>Activity Name:/b></label>          
  3.         <select name="activity" id="activity" required>
  4.         <script>
  5.             function getActivity(tx) {
  6.                 tx.executeSql('SELECT * FROM tblactivity', [], queryActivity, errorHandler);
  7.                     function queryActivity(tx, results) {
  8.                 var len = results.rows.length;
  9.                 for (var i = 0; i < len; i++) {
  10.                    var SelectActivity +='<option value="' + results.rows.item(i).activityID +'">'+ results.rows.item(i).ActivityName +'</Option>';
  11.                 }
  12.                 //SelectActivity +="</Option";
  13.                 document.getElementById("activity").innerHTML =SelectActivity;
  14.             }}
  15.         </script>
  16.         </select>
Apr 7 '18 #1
1 5234
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.
Apr 11 '18 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: djharrison | last post by:
I'm new to ASP and database programming but I am trying to connect to a database using a concatenation of a strings and a menu item from a form. Ok here's what I have... an asp form that has a...
4
by: Tim | last post by:
Hi, I've been searching the web for hours now and found lots and lots of javascript files with which you can create dropdown menu's, but with all of them you have to specify the width of the...
1
by: pawarsac | last post by:
Hello I am new to PHP. I want to create DropDown menu. When user hovers mouse over the text in menu, subcategory should be dropped down. How to create such PHP page and javascript for this ? ...
1
akhan
by: akhan | last post by:
i used the following code to enter data in dropdown menu : <? $con=mysql_connect("","",""); mysql_select_db('investment',$con); $query="select *from personal_info"; $res =...
3
by: Ninio | last post by:
I have a simple form with a dropdown menu that consists of 3 option and each option should retrieve a query from a database. i have been looking all over the place and can't seem to find how to do...
10
by: Chuck Anderson | last post by:
Firefox 3 uses sqlite files for bookmarks, browse history, form history, cookies, ...... When I execute : $sqlite_db_file = 'cookies.sqlite'; $db = sqlite_open($sqlite_db_file, 0666,...
3
by: tceramesh | last post by:
Hi Friends, I Created one drop down menu by using CSS. It is perfect in Firefox but in IE it creates some problem. in the header section the drop down menu appear,, below that...
5
by: enrekan2011 lan | last post by:
haii... im new here and in php coding as well.. sorry if im ask stupid question here.. i just need some help from you all because i have try find at google but i still didn't found the...
3
by: reigns7703 | last post by:
Hi all! I am a newbie and unfamiliar with PHP and MySQL... I am trying to create a dropdown menu that defaults to all items in my database while still allowing one to also filter to certain...
4
by: reigns7703 | last post by:
$query_Test = "SELECT * FROM Products WHERE Product_Type='$Product_Type' ORDER BY Product_Title ASC"; $query_limit_Test = sprintf("%s LIMIT %d, %d", $query_Test, $startRow_Test, $maxRows_Test);...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.