I have coded some ajax recently but whenever I click the 'register' button, nothing actually happens. I worked about about an hour to check what's wrong with the code but I failed to find any error. My php file just displays out an echo and runs some code if required POST data is set. I can run the php file and it works just fine but I cannot get Ajax to load the php file even. Can you check my script for any error?
<?php
require 'includes/core.inc.php';
require 'includes/connect.inc.php';
?>
<link rel=StyleSheet src='themes/<?php echo $theme; ?>/mainstyle.css' type='text/css'>
<script type='text/javascript'>
function registeraccount(id){
if (window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
xmlhttp = new ActiveXObject('Microsoft.XMLHttp');
}
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById(id).innerHTML = xmlhttp.responseText;
}
}
var username = document.register.username.value;
var password = document.register.password.value;
var password2 = document.register.password2.value;
var email = document.register.email.value;
var firstname = document.register.firstname.value;
var lastname = document.register.lastname.value;
var querystring = "username="+username+"&password="+password+"&password2="+password2+"&email="+email+"&firstname="+firstname+"&lastname="+lastname;
xmlhttp.open('POST', 'includes/registeraccount.php' + querystring, true);
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttp.send(querystring);
}
</script>
<form name='register' action='' method='POST'>
<fieldset class='fieldset'>
<legend class='legend'>Register</legend>
<p class='basicbox'>Note: All the fields marked with * are mandatory</p>
<div id='result'></div><br>
<span>Username</span> <input type='text' name='username' class='textboxbasic'/><br>
<span>Password</span> <input type='password' name='password' class='textboxbasic' "/><br>
<span>Password again</span> <input type='password' name='password2' class='textboxbasic'"/><br>
<span>Email address</span> <input type='text' name='email' class='textboxbasic'/><br>
<span>First name</span> <input type='text' name='firstname' class='textboxbasic'/><br>
<span>Last name</span> <input type='text' name='lastname' class='textboxbasic'/><br>
<button class='submitbutton' onClick="registeraccount('result')">Register</button>
</fieldset>
</form>