Results 1 to 4 of 4

Thread: javascript error.using javascript to access ms access table records

  1. #1
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default javascript error.using javascript to access ms access table records

    hi
    i m using javascript to get data from ms access.
    the search is working fine but i m unable to save the new records
    i m unable to find out the problem in the script
    can anyone help me in this regard?
    ps-i m new to javascript and also to this forum
    <html>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <script language="JavaScript">
    function ResetForm()
    {
    document.getElementById("txtACDATE").value = "";
    document.getElementById("txtASNO").value = "";
    document.getElementById("txtPCS").value = "";
    document.getElementById("txtSP").value = "";
    document.getElementById("txtRE").value = "";
    document.getElementById("btnSave").disabled = false;
    }

    function SaveForm()
    {
    try
    {
    var cn = new ActiveXObject("ADODB.Connection");
    cn.Mode = 3;
    var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ="+getDBFile()+";Persist Security Info=False";
    cn.Open(strConn);
    if(document.getElementById("txtClId").value =="")

    {
    var SQL = "insert into receive (ACDATE , ASNO , PCS , SP , RE)" +
    "values ";
    SQL = SQL + "('" +
    document.getElementById("txtACDATE").value + "','" +
    document.getElementById("txtASNO").value + "','" +
    document.getElementById("txtPCS").value + "','" +
    document.getElementById("txtSP").value + "','" +
    document.getElementById("txtRE").value + "')";
    cn.Execute(SQL);
    alert("New Record Saved Successfully");
    document.getElementById("btnSave").disabled = true;
    }
    else
    {
    var SQL = "Update receive set " +
    "ACDATE = '" + document.getElementById("txtACDATE").value + "'," +
    "ASNO = '" + document.getElementById("txtASNO").value + "'," +
    "PCS = '" + document.getElementById("txtPCS").value + "'," +
    "SP = '" + document.getElementById("txtSP").value + "'," +
    "RE = '" + document.getElementById("txtRE").value + "'" +
    "where ClId = " + document.getElementById("txtclid").value ;
    cn.Execute(SQL);
    alert("Client Master Successfully Updated!!!!");
    document.getElementById("btnSave").disabled = true;
    }
    cn.Close();
    ResetForm();

    }
    catch (e)
    {
    alert("Error SaveForm() : " +e);
    }
    }
    function getDBFile()
    {
    var dbfile = location.href;
    var idx=location.href.indexOf('receivedalt.htm');
    dbfile= dbfile.substr(0, idx) + "receivedalt.mdb" ;
    return dbfile.substr(8);
    }
    function getClientDetails(clid)
    {
    try
    {
    var dbfile = getDBFile();
    var cn = new ActiveXObject("ADODB.Connection");
    var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ="+ dbfile+ ";Persist Security Info=False";
    cn.Open(strConn);
    var rs = new ActiveXObject("ADODB.Recordset");
    var SQL = "Select * from receive where ClId = " + clid;
    rs = cn.Execute(SQL);
    if (!rs.EOF)
    {
    document.getElementById("txtclid").value = rs("ClId");
    document.getElementById("txtACDATE").value = rs("ACDATE");
    document.getElementById("txtASNO").value = rs("ASNO");
    document.getElementById("txtPCS").value = rs("PCS");
    document.getElementById("txtSP").value = rs("SP");
    document.getElementById("txtRE").value = rs("RE");
    document.getElementById("btnSave").disabled = false;
    }
    }
    catch(e)
    {
    alert ("getClientDetails() : " + e);
    }
    }

    function getSearchResults()
    {
    try
    {
    var para = document.getElementById("txtSearchPara").value;
    var dbfile = getDBFile();
    var cn = new ActiveXObject("ADODB.Connection");

    var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ="+ dbfile+ ";Persist Security Info=False";
    cn.Open(strConn);
    var rs = new ActiveXObject("ADODB.Recordset");

    var SQL = "select * from receive where " +
    "ACDATE like '%" + para + "%' or " +
    "ASNO like '%" + para + "%' or " +
    "PCS like '%" + para + "%' or " +
    "SP like '%" + para + "%' or " +
    "RE like '%" + para + "%' order by ASNO , ACDATE";
    rs = cn.Execute(SQL);
    var resultString = "<table style = 'position: relative; width: 100%; height: 100%;' border = 1>";
    resultString = resultString + "<tr> " +
    "<td></td>" +
    "<td></td>" +
    "<td></td>" +
    "<td></td>" +
    "<td></td>" +
    "<td></td>" +
    "<td></td>" +
    "<td></td>" +
    "</tr>" ;
    while (!rs.EOF )
    {
    resultString = resultString + "<tr> " +

    "<td><b>" + "Alteration No = " + rs("ASNO")+ "</b></td>" +

    "</tr>" +
    "<tr>" +

    "<td>" + "Ready Date = " + rs("ACDATE") + "</td>" +
    "<td>" + "No of Pcs. = " + rs("PCS") + "</td>" +
    "<td>" + "Sales Person = " + rs("SP") + "</td>" +
    "</tr>" +


    "<tr> " +

    "<td>" + "Remarks = " + rs("RE") + "</td>" +
    "</tr>" +


    "<tr style='height:18'> " +
    "<td></td>" +
    "<td></td>" +
    "<td></td>" +
    "</tr>"
    ;


    rs.MoveNext();
    }
    resultString = resultString + "</table>";
    rs.Close();
    cn.Close();
    document.getElementById("SearchResultPanel").innerHTML = resultString;

    }
    catch (e)
    {
    alert ("getSearchResults() : " + e);
    }
    }
    </script>
    </head>
    <body>
    <div style="position: relative; width: 100%; height: 100%; z-index: 1" id="MainPage">
    <table style = "position: relative; width: 100%; height: 100%;" >
    <tr style = "height:100">
    <td>
    <p align="center"><b><font size="6" face="Arial">ALTERATION STITCHING ENTRY(RECEIVED AFTER ALT/STIT)</font></b>
    </td>
    </tr>
    <tr style="height:50">
    <td background = "#3300ff">
    <table style = "position: relative; width: 100%; height: 100%;">
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td>
    <table style = "position: relative; width: 100%; height: 100%;">
    <tr style = "height: 50">
    <td>
    <table style = "position: relative; width: 100%; height: 50;">
    <tr>
    <td>
    <p align="center">
    <input type="button" value="Refresh" name="btnRefresh" tabindex="7" onclick = "ResetForm();" style="float: left"><input type="button" value="Save" name="btnSave" tabindex="6" onclick = "SaveForm();" style="float: left"></td>
    <td>&nbsp;</td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td>
    <table style = "position: relative; width: 100%; height: 100%;" border = 1><tr><td>
    <form id="ClientMaster" >
    <table style = "position: relative; width: 100%; height: 100%;">
    <tr>
    <td>ID</td>
    <td>
    <input type="text" name="txtClId" disabled="true" size="20">
    </td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    <tr>
    <td>RECEIVED DATE</td>
    <td>
    <input type="text" name="txtACDATE" tabindex="1" size="20">
    </td>

    <td>ALT/STIT.NO.</td>
    <td>
    <input type="text" name="txtASNO" tabindex="2" size="20">
    </td>

    <td>NO.OF PCS.</td>
    <td>
    <input type="text" name="txtPCS" tabindex="3" size="20">
    </td>
    <td>SALES PERSON</td>
    <td>
    <input type="text" name="txtSP" tabindex="4" size="20" >
    </td>
    </tr>
    <tr>
    <td>REMARKS</td>
    <td>
    <input type="text" name="txtRE" tabindex="5" size="20">
    </td>
    </tr>


    </table>
    </form>
    </td></tr></table>
    </td>
    </tr>
    <tr>
    <td>
    <table style = "position: relative; width: 100%; height: 100%;">
    <tr>
    <td>
    Master Search <input type="text" name="txtSearchPara" tabindex="8" onblur = "getSearchResults();" size="20">
    </td>
    </tr>
    <tr>
    <td>
    <SPAN id= "SearchResultPanel" style = 'position: relative; width: 100%; height: 100%;' > </SPAN>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </body>

  2. #2
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Code:
    <input type="text" id="txtACDATE" tabindex="1" size="20">
    Also, you need to move your script tag AFTER the tags that it uses. Aka: All the document.getElementsById("ABC") currently do no know what ABC is, but if you move the ABC element before your script tag, then it knows.
    Trinithis

  3. #3
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default

    thanks a million
    thanks for the help

  4. #4
    Join Date
    Sep 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hai Meenakshi,

    I am murali from chennai. I saw ur article in this. very nice. i am working in software in jave script. i needed some tips. i need javascript with access along with database. i saw this in ur project. can u give me ur project coding with database connectivity. Please send ur project in my personal id rajanmur@gmail.com. If u wish. Kindly do the needful.

    Thank you

    Regards
    Murali.r
    Shanthi.g

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
  •