populating text from database

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default populating text from database

    I am trying to populate multiple textboxes from an Access database. I
    am trying to write code to generate the appropriate number of
    textboxes based upon the number of records in the access table. I am
    getting lost with the code...Here's what I've got:

    <%@ language = "Javascript" %>
    <%

    var strJob = "";
    strJob = Request.Form("txt");

    var strconnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
    Source=C:/Inetpub/wwwroot/ITI/fpdb/resume04.mdb";
    %>
    <script language=Javascript>

    function initControls()
    {
    populateJob();
    }

    function build() {
    var num = 0;
    var tbl = "<table border='0'>\n";
    for (var i=0; i<10; i++) {
    tbl += "<tr>\n";
    for (var j=0; j<4; j++) {
    tbl += " <td>\n";
    tbl += " <input type='radio' name='box' value='Box" +
    num
    + "'>\n";
    tbl += " </td>\n";
    num++;
    }
    tbl += " <td>\n";
    tbl += " <input type='text' name='txt" + num + "'
    value=''>\n";
    tbl += " </td>\n";
    tbl += "</tr>\n";
    }
    tbl += "</table>\n";
    document.write(tbl);
    }

    function populateJob()
    {
    <%
    var rs = Server.CreateObject("ADODB.Recordset");
    var sql = "select distinct Preference from Preferences"
    rs.Open(sql,strconnection);
    var n=0;
    while (!rs.EOF)
    {
    var stateID = rs.Fields("Preference");
    var stateDesc = rs.Fields("Preference");
    Response.Write("document.repForm.txt[" + n + "] = new value('" +
    stateDesc+ "','" + stateID + "');");

    if (new String(strJob).search(stateID) != -1)

    Response.Write("document.repForm.txt[" + n + "].selected = true;");
    rs.MoveNext();
    n++;
    }
    rs.Close();
    %>

    }

    </script>

    <html>
    <head>
    <title>Resume</title>
    </head>
    <BODY onload = "initControls();" >
    <form method="post" onsubmit="return check()">
    <language = "javascript">
    BUILD()
    </script>
    <input type="submit" value="submit">
    <input type="reset" value="clear">
    </form>
    </body>
    </html>

    Thanks!
    Jeremy Guest

  2. Similar Questions and Discussions

    1. Populating Drop Down Boxes from a database
      We moved our wesite from a Box running Coldfusion 4.0 to a box running Coldfusion MX. We populate some drop down boxes with information from a...
    2. Web Form Populating Database
      Publisher 2003. Web form set to save the data in a comma-delimeted text file on my web server. Form working well, I'm able to use the wizard in...
    3. Populating three list boxes from the database
      Can anybody help? I need to have three list boxes automatically populating each other, (ie when region is selected from the first listbox, it will...
    4. populating radiobuttonlist from database programmatically
      I store radiobuttonlist values in the db using the string value of the radio button item value. (nvarchar) I am creating an edit functionality on...
    5. Populating another database with records from an asp page.
      Apologies for the length of this mail but code is included. Have a page that pulls data from one database & displays the results, using a loop to...
  3. #2

    Default Re: populating text from database

    "Jeremy" <jeremy_zifchock@yahoo.com> wrote in message
    news:f9d85033.0401060730.182291eb@posting.google.c om...
    > I am trying to populate multiple textboxes from an Access database. I
    > am trying to write code to generate the appropriate number of
    > textboxes based upon the number of records in the access table. I am
    > getting lost with the code...Here's what I've got:
    >
    > <%@ language = "Javascript" %>
    > <%
    >
    > var strJob = "";
    > strJob = Request.Form("txt");
    >
    > var strconnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source=C:/Inetpub/wwwroot/ITI/fpdb/resume04.mdb";
    > %>
    > <script language=Javascript>
    >
    > function initControls()
    > {
    > populateJob();
    > }
    >
    > function build() {
    > var num = 0;
    > var tbl = "<table border='0'>\n";
    > for (var i=0; i<10; i++) {
    > tbl += "<tr>\n";
    > for (var j=0; j<4; j++) {
    > tbl += " <td>\n";
    > tbl += " <input type='radio' name='box' value='Box" +
    > num
    > + "'>\n";
    > tbl += " </td>\n";
    > num++;
    > }
    > tbl += " <td>\n";
    > tbl += " <input type='text' name='txt" + num + "'
    > value=''>\n";
    > tbl += " </td>\n";
    > tbl += "</tr>\n";
    > }
    > tbl += "</table>\n";
    > document.write(tbl);
    > }
    >
    > function populateJob()
    > {
    > <%
    > var rs = Server.CreateObject("ADODB.Recordset");
    > var sql = "select distinct Preference from Preferences"
    > rs.Open(sql,strconnection);
    > var n=0;
    > while (!rs.EOF)
    > {
    > var stateID = rs.Fields("Preference");
    > var stateDesc = rs.Fields("Preference");
    > Response.Write("document.repForm.txt[" + n + "] = new value('" +
    > stateDesc+ "','" + stateID + "');");
    >
    > if (new String(strJob).search(stateID) != -1)
    >
    > Response.Write("document.repForm.txt[" + n + "].selected = true;");
    > rs.MoveNext();
    > n++;
    > }
    > rs.Close();
    > %>
    >
    > }
    >
    > </script>
    >
    > <html>
    > <head>
    > <title>Resume</title>
    > </head>
    > <BODY onload = "initControls();" >
    > <form method="post" onsubmit="return check()">
    > <language = "javascript">
    > BUILD()
    > </script>
    > <input type="submit" value="submit">
    > <input type="reset" value="clear">
    > </form>
    > </body>
    > </html>
    >
    > Thanks!

    I'm guessing your code is trying to populate a table built on the
    client-size (via "build()") with server-side data per "populateJob()".
    Ain't gonna happen! Server-side code executes first. Try building the
    entire table server-side; such as:

    <% @language = "Javascript" %>
    <%
    // Build Array
    .................................................. ................
    var job = Request.Form("txt");
    var mdb = "C:/Inetpub/wwwroot/ITI/fpdb/resume04.mdb";
    var ado = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=" + mdb;
    var sql = "select distinct Preference from Preferences"
    var rst = Server.CreateObject("ADODB.Recordset");
    rst.Open(sql,ado);
    var n = 0;
    var stateID = new Array();
    var stateDesc = new Array();
    while (!rst.EOF) {
    stateID[n] = rst.Fields("Preference");
    stateDesc[n] = rst.Fields("Preference");
    n++;
    rst.MoveNext();
    }
    rst.Close();
    // Build Table
    .................................................. ................
    var num = 0;
    var val;
    var tbl = "<table border='0'>\n";
    for (var i=0; i<n; i++) {
    tbl += "<tr>\n";
    for (var j=0; j<4; j++) {
    var chk = "";
    if (job.stateID[i] != -1) chk = " checked";
    tbl += " <td>\n";
    tbl += " <input type='radio' name='box' value='Box" + num + "' +
    chk + ">\n";
    tbl += " </td>\n";
    num++;
    }
    val = stateDesc[i] + "," + stateID[i];
    tbl += " <td>\n";
    tbl += " <input type='text' name='txt" + num + "' value='" + val +
    "'>\n";
    tbl += " </td>\n";
    tbl += "</tr>\n";
    }
    tbl += "</table>\n";
    %>
    <html>
    <head>
    <title>Resume</title>
    <script language="javascript" type="text/javascript">
    function check() {
    // { check something }
    return true;
    }
    // -->
    </script>
    </head>
    <body>
    <form method="post" name="RepForm" onsubmit="return check()">
    <%=tbl%>
    <input type="submit" value="submit">
    <input type="reset" value="clear">
    </form>
    </body>
    </html>


    P.S. I'm not sure if my snippet
    if (job.stateID[i] != -1)
    is the same as yours
    if (new String(strJob).search(stateID) != -1)

    Note: the above is pseudo-code. You may have to tweak it to get it to work.
    Watch for word-wrap.


    McKirahan Guest

  4. #3

    Default Re: populating text from database

    Actually, here is a more concise version of the script I'm haing
    trouble with...

    <%@ language = "Javascript" %>
    <%
    var strJob = "";
    var strconnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
    Source=C:/Inetpub/wwwroot/ITI/fpdb/resume04.mdb";
    %>
    <script language=Javascript>
    function populateJob()
    {
    <%
    var rs = Server.CreateObject("ADODB.Recordset");
    var sql = "select distinct Preference from Preferences"
    rs.Open(sql,strconnection);
    var n=0;
    while (!rs.EOF)
    {
    var pref = rs.Fields("Preference");
    {
    var tbl = "<table border='0'>\n";
    {
    tbl += "<tr>\n";
    for (var j=0; j<4; j++)
    {
    tbl += " <td>\n";
    tbl += " <input type='radio' name='box' value='Box"
    + n + "'>\n";
    tbl += " </td>\n";
    }
    tbl += " <td>\n";
    tbl += " <input type='text' name='txt" + n + "' value='"
    + pref + "'>\n";
    tbl += " </td>\n";
    tbl += "</tr>\n";
    }
    tbl += "</table>\n";
    Response.Write("document.repForm.write('" + tbl + "')");
    }
    rs.MoveNext();
    n++;
    }
    rs.Close();
    %>
    }
    </script>
    <html>
    <head>
    <title>Resume</title>
    </head>
    <BODY onload = "PopulateJob();" >
    <form name="repForm" method="post" onsubmit="return check()">
    <input type="submit" value="submit">
    <input type="reset" value="clear">
    </form>
    </body>
    </html>
    Jeremy Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139