Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
code for index.html

XML
<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;
} // end if
} // end anonymous call-back function
xhr.send(requestbody);
} // end if
} // end function getData()


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>
Posted
Updated 26-Apr-15 5:50am
v2
Comments
Mohibur Rashid 26-Apr-15 20:22pm    
Your question make no sense. Please try to rephrase it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900