Results 1 to 2 of 2

Thread: populate listbox from a database in html

  1. #1
    Join Date
    Sep 2013
    Posts
    10

    populate listbox from a database in html

    Hi

    i have the following html code that is working.
    <html>
    <head>
    <title>Entitled Document</title>
    <script language="JavaScript" >

    function condb()
    {

    var cn = new ActiveXObject("ADODB.Connection");
    var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = d:\siel.mdb";
    var rs = new ActiveXObject("ADODB.Recordset");
    var SQL = "select fname, mname, lname from hd where fname = 'Joe'";
    cn.Open(strConn);
    rs.Open(SQL, cn);

    fname.value = rs(0);
    lname.value = rs(2);
    mname.value = rs(1);
    rs.Close();
    cn.Close();

    }

    </script>
    </head>
    <body>

    <br />
    &nbsp;

    First <input type="text" name="fname" />&nbsp;
    Middle
    <input type="text" name="mname" />
    Last <input type="text" name="lname" />
    <input type="button" value="submit" onClick="condb()">&nbsp;

    </body>
    </html>

    I want to store the dataset in an array then use it to populate a listbox.
    and I need the listbox.value to be lname
    can you help ?
    thank you

  2. #2
    Join Date
    Sep 2013
    Posts
    10

    Re: populate listbox from a database in html

    I have the following html code:

    <html>
    <body>
    <script language="javascript">
    var cn = new ActiveXObject("ADODB.Connection");
    var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\contact.mdb";
    var rs = new ActiveXObject("ADODB.Recordset");
    var rs2 = new ActiveXObject("ADODB.Recordset");
    var SQL = "select fname, mname, lname from hd where fname = 'joe'";
    var SQL2= "select count(fname) as rcount from hd where fname = 'joe'";
    rst=cn.Open(strConn);
    rs1=rs.Open(SQL, cn);
    rs0=rs2.Open(SQL2, cn);

    rcnt= rs2(0);
    var numArr = new Array (rcnt);
    var i;
    var j;
    for (i = 0; i < rcnt; i++)
    {
    numArr[i] = rs(0);
    }
    i = 0;
    while (i < rcnt)
    {
    //document.write ("numArr[" + i + "] = " + numArr[i] + "<br>");;
    i++;
    }
    </script>

    <script type="text/javascript">
    <!--

    function populateList() {

    for (var loop=0; loop<numArr.length; loop++) {
    var tempOpt = new Option(numArr[loop], numArr[loop]);
    document.getElementById('locationList').options.add(tempOpt);

    }
    }

    onload = populateList;
    //-->
    </script>

    <tr>
    <td colspan="2"><p>Populate list box from array :
    <select name="locationList" id="locationList" size="4" onChange="alert(value);
    tf.value=value;" style="font-family:arial; font-size:12; color:#000000; text-decoration:none; padding-left:10px; width:200px; border:2;">
    </select>
    </p>
    <p>
    </body>
    </html>

    I am trying to create a list box that holds fname from table hd and the value lname.

    I dont know what to do next. so can anyone help and suggest what to do next.
    thank you

Similar Threads

  1. Populate a list box
    By See29596 in forum Software Development
    Replies: 1
    Last Post: 26-09-2013, 11:34 AM
  2. How to create ListBox in VB.net?
    By MarceloQuad in forum Software Development
    Replies: 4
    Last Post: 22-01-2010, 08:44 PM
  3. HTML Listbox ActiveX Control
    By Chrisch in forum Software Development
    Replies: 3
    Last Post: 11-08-2009, 03:04 PM
  4. C# Listbox control
    By abhinavm in forum Software Development
    Replies: 2
    Last Post: 07-08-2009, 11:01 PM
  5. Combobox Selection To Populate Listbox
    By mellisahi in forum Software Development
    Replies: 3
    Last Post: 06-06-2009, 10:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,548,364.22842 seconds with 17 queries