erroe while updating XML file using ASP and javascript

Discussion in 'C#' started by Sujata321, Aug 15, 2009.

  1. #1
    Hi,
    I need to update an XML file using ASP and javascript/vbscript.

    But this is not working.It is showing the error – ‘document’ is not defined –in the line
    str1=document.getElementById('D1').value;

    Kindly someone can help me regarding this.


    Here is my Code using ASP and Javascript:
    [Note: here I have not written the HTML in detail as there are many controls in the page.]

    <% @LANGUAGE="javascript" %>
    <html>
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Update</title>
    <script language="javascript">

    <%
    function update_test()

    {
    xmlDoc = Server.CreateObject("Microsoft.XMLDOM");
    xmlDoc.async = false;
    xmlDoc.load (Server.MapPath("config_data.xml"));
    %>
    confirm('Do you want to update this value');

    str1=document.getElementById('D1').value;
    str2=document.getElementById('D2').value;
    str3=document.getElementById('T8').value;
    str_script=document.getElementById('T11').value;
    str_path=document.getElementById('T12').value;
    str_suit=document.getElementById('T13').value;
    str_dir=document.getElementById('T14').value;

    x1= xmlDoc.getElementsByTagName(str1)[0].getElementsByTagName('tests');
    for (i=0;i<x1.length;i++)
    {
    if((x1.item(i).attributes[0].value)==str2)
    {
    old_value=x1.item(i).attributes[0].name;
    x1.setAttribute(old_value,str3);
    x2=x1.item(i).getElementsByTagName("prerequisitescript")
    for (l=0;l<x2.length;l++)
    {
    x2[l].text=str_script;
    }
    x3=x1.item(i).getElementsByTagName("acbuildpath")
    if(x3[0].hasChildNodes())
    {
    x3[0].text=str_path;
    }
    x4=x1.item(i).getElementsByTagName("testsuitscript")

    if(x4[0].hasChildNodes())
    {
    x4[0].text=str_suit;
    }
    x5=x1.item(i).getElementsByTagName("testdir")

    if(x5[0].hasChildNodes())
    {
    x5[0].text=str_dir;
    }

    }
    }

    <%
    xmlDoc.save("config_data.xml");
    %>

    alert("Data Updated");
    <%
    }
    %>

    </script>
    <body>
    <form method="POST" action="--WEBBOT-SELF--" onSubmit="">

    <img border="0" id="img6" src="images/button50.gif" height="20" width="100" alt="Update" fp-title="Update" onclick=<%update_test()%>></a></p>
    </form>
    </body>
    </html>

    Thanks……….
     
    Sujata321, Aug 15, 2009 IP