<html>
<head><script type="text/javascript" language="javascript">
var http_request = false;
function POSTrequest(sssfile, data) {
http_request = false;
if(window.XMLHttpRequest) { // Code for firefox, opera, safari, etc...
http_request = new XMLHttpRequest();
if(http_request.overrideMimeType) {
http_request.overrideMimeType('text/html');
// http_request.overrideMimeType('text/xml');
}
}
else if(window.ActiveXObject) { // Code for IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(error) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(error) { }
}
}
if(!http_request) {
alert("Cannot create XMLHTTP instance");
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('POST', sssfile, true);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", data.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(data);
}
function alertContents() {
if(http_request.readyState == 4) {
if(http_request.status == 200) {
result = http_request.responseText;
document.getElementById('myspan').innerHTML = result;
}
else {
alert("Er was een probleem bij het verwerken van de data.");
}
}
}
function get(obj) {
var poststr = "";
for (i=0; i < obj.getElementsByTagName("input").length; i++) {
if (obj.getElementsByTagName("input")[i].type == "text") {
poststr += obj.getElementsByTagName("input")[i].name + "=" +
obj.getElementsByTagName("input")[i].value + "&";
}
if (obj.getElementsByTagName("input")[i].type == "checkbox") {
if (obj.getElementsByTagName("input")[i].checked) {
poststr += obj.getElementsByTagName("input")[i].name + "=" +
obj.getElementsByTagName("input")[i].value + "&";
} else {
poststr += obj.getElementsByTagName("input")[i].name + "=&";
}
}
if (obj.getElementsByTagName("input")[i].type == "radio") {
if (obj.getElementsByTagName("input")[i].checked) {
poststr += obj.getElementsByTagName("input")[i].name + "=" +
obj.getElementsByTagName("input")[i].value + "&";
}
}
if (obj.getElementsByTagName("input")[i].tagName == "SELECT") {
var sel = obj.getElementsByTagName("select")[i];
poststr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
}
}
}
POSTrequest('includes/showMessage.include.php', poststr);
</script>
</head>
<body><div>
<form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform">
<tr><td><input type="text" name="test" value="teststring"><br></td></tr>
<input type="radio" name="myradio" value="0" checked> 0
<input type="radio" name="myradio" value="1"> 1<br>
<input type="checkbox" name="mycheck1" value="1"> 1
<input type="checkbox" name="mycheck2" value="2"> 2
<input type="checkbox" name="mycheck3" value="3"> 3
<input type="checkbox" name="mycheck4" value="4"> 4
<input type="checkbox" name="mycheck5" value="5"> 5
<br>
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<br>
<textarea name="text">blaaa</textarea>
<br />
<input type="button" name="button" value="Submit"
onclick="javascript:get(this.parentNode);">
<input type="submit" name="button" value="Normal Submit Button">
</form></div>
<br><br>
Server-Response:<br>
<span name="myspan" id="myspan"></span>
</body></html>