Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to add rows to a table ?

    I am trying to get this script to run. It is supposed to take the data from a resultset and feed it into a table. In have set up the table.
    <div CLASS="datafields" ID="showresults" >
    <table id="resultrows">
    </table>
    </div>
    And have put together the script the returning data from a database works fine. Its just the adding of child elements to the table that is driving me up the wall!!!!!!!

    Just to fill in some holes this is all done client side no webserver can or is used the variable ReturnDataTo="resultrows"

    function getResults(DataSearchField, DataSearchValue, SearchErrorMsgId, ReturnDataTo ) {

    var adOpenForwardOnly=0, adLockReadOnly=1;

    var conn = new ActiveXObject("ADODB.Connection");
    conn.Open("Provider=" + db1provider + ";Data Source=" + db1path + ";Persist Security Info=False;");

    if (conn)
    { var rs = new ActiveXObject("ADODB.Recordset");
    rs.Open("SELECT * FROM staffdetails WHERE " + DataSearchField + "='" + DataSearchValue + "' ", conn, adOpenForwardOnly, adLockReadOnly);

    var rowelement,datatable;
    rowelement=document.createElement('tr');
    rowelement.innerHTML="<td>DB REF</td><td>COST CENTER</td><td>FIRST NAME</td><td>LAST NAME</td><td>PCICS ID</td>";
    datatable=document.getElementById(ReturnDataTo);
    datatable.appendChild(rowelement);

    while(!rs.eof) {
    var ret_dbref=rs("dbref");
    var ret_costcenter=rs("costcenter");
    var ret_firstname=rs("firstname");
    var ret_lastname=rs("lastname");
    var ret_pcicsid=rs("pcicsid");

    rowelement=document.createElement('tr');
    rowelement.innerHTML="<td>" + ret_dbref + "</td><td>" + ret_costcenter + "</td><td>" + ret_firstname + "</td><td>" + ret_lastname + "</td><td>" + ret_pcicsid + "</td> ";
    datatable=document.getElementById(ReturnDataTo);
    datatable.appendChild(rowelement);

    rs.MoveNext();
    }
    rs.Close();
    } else {
    obj=document.getElementById(SearchErrorMsgId);
    obj.innerHTML="<b>UNABLE TO CONNECT PLEASE RETRY!</b>";
    }
    conn.close();
    }

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't know about all the ADO stuff, but regarding adding to the table, I know that TBODY is usually the culprit.

    Ensure that you are adding rows to a TBODY, and not to a TABLE.

    Code:
    <table id="result_table">
     <tbody id="result_tb">
     </tbody>
    </table>
    So ReturnDataTo should hold "result_tb".

    Hope that helps,
    Sadiq.


  •  

    Posting Permissions

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