The code contain a function through which i have to add new node in XML file and below that there are 2 text boxes and a submit button, i think there is problem in saving xml file through javasrcipt function.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function addElement()
{
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
var root;
var newNode;
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("user.xml");
try
{
root = xmlDoc.documentElement;
alert(root.xml);
var n1 =document.getElementById("t1").value;
var p1 =document.getElementById("t2").value;
newNode = xmlDoc.createElement("user");
var name =xmlDoc.createNode(1, "name", n1);
var pass = xmlDoc.createNode(1, "pass", p1);
newNode.appendChild(name);
newNode.appendChild(pass);
root.appendChild(newNode);
alert(root.xml);
xmlDoc.save("user.xml");
document.WriteString(root.lastChild.nodeValue);
alert("added");
}
catch(e)
{
alert("error");
}
}
</script>
</head>
</head>
<body>
<form id="user_form" method="post">
<table>
// textbox1
<tr>
<td>Name :</td><td><input type="text" id="t1"></td>
</tr>
// textbox2
<tr>
<td>Password :</td><td><input type="text" id ="t2"></td>
</tr>
//submit button
<tr>
<td><input type ="Submit" id="b1" onclick="addElement()"></td>
</tr>
</table>
</form>
</body>
</html>
No comments:
Post a Comment