code for index.html
<html>
<body>
<table align="center" border="0" cellpadding="1" cellspacing="1" style="width: 500px;">
<form name="form" action="form.php" method="post">
<tbody>
<tr>
<td>ID:</td>
<td><input type="text" id="id_code" name= "id_code" /></td>
</tr><br/>
<tr>
<td>VALUE:</td>
<td><input type="text" id="id_value" name= "id_value"/></td>
</tr><br/>
<tr align="center">
<td><input name="submit" type = "button" onClick = "getData('form.php', id_code.value,id_value.value)" value = "Add Data" />
<button type="reset" value="Reset">Reset</button></td>
</tr><br/>
</tbody>
</form>
</table>
</body>
</html>
code for form.js
<script src="jquery-1.4.2.min">
var xhr = createRequest();
function getData(dataSource,id_code,id_value) {
if(xhr) {
var obj = document.getElementById(divID);
var requestbody ="idd="+encodeURIComponent(id_code)+"&itd="+encodeURIComponent(id_value);
xhr.open("POST", dataSource, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
obj.innerHTML = xhr.responseText;
}
}
xhr.send(requestbody);
}
}
code for form.php
<?php
<script type="text/javascript" src="form.js" src="jquery-1.4.2.min"></script>
$post_id_code= $_POST["idd"];
$post_id_value = substr($_POST["itd"], 0,10);
$xml = new DomDocument();
$xml->load("form.xml");
$xml->formatOutput = true;
$global = $xml->documentElement;
$global = $xml->firstChild;
$item = $xml->createElement('item');
$global->appendChild($item);
$id_code = $xml->createElement('id_code');
$idvalue = $xml->createElement('idvalue');
$item->appendChild( $id );
$id_code->nodeValue = $post_id_code;
$item->appendChild( $idvalue );
$idvalue->nodeValue = $post_id_value;
$xml->save("form.xml");
?>
I want my form.xml file to be like
<?xml version="1.0" encoding="UTF-8"?>
<global>
<item>
<id="12" value="numbering">
<id="123" value="counting">
</item>
</global>