Hello DaniWeb! I am having a particular problem with my Javascript page, which should change the form that the user is at. Can anyone proofread my code to check for errors? The code does not change the form (Also it does not run the PHP page, or at least does not display its output in the loginStatus div):
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<title>
PHP Hardcoded Login Script!
</title>
<script>
function processLogin(form) {
var user = form.user.value;
var pass = form.pass.value;
var url = "processLogin.php?user=" + user + "&pass=" + pass;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET",url,false);
xmlhttp.send(null);
document.getElementById('loginStatus').innerHTML=xmlhttp.responseText;
}
function writeLogin() {
document.getElementById('inputArea').innerHTML = "
<form name=\"loginForm\" id=\"loginForm\" action=\"\" method=\"post\">
<h3>User: </h3><input type=\"text\" name=\"user\" />
<h3>Pass: </h3><input type=\"password\" name=\"pass\"/>
<br/>
<INPUT TYPE=\"button\" NAME=\"submitButton\" Value=\"Submit\" onClick=\"processLogin(this.form)\">
<input type=\"button\" value=\"Create Username\" id=\"newUser\" onClick=\"writeSignup()\"/>
</form>";
}
function writeSignup(form) {
var signupDiv = document.getElementById('inputArea').innerHTML ="
<form name=\"newUserForm\" id=\"newUserForm\" action=\"\" method=\"post\">
<h4>Prefered Username: </h4>
<input type=\"text\" name=\"user\" />
<h4>Password: </h4>
<input type=\"password\" name=\"pass\"/><br/>
<h4>Confirm Password: </h4>
<input type=\"password\" name=\"passConf\"/>
<h4>Email: </h4>
<input type=\"text\" name=\"email\"/>
<br/>
<input type=\"button\" name=\"submitButton\" value=\"Create User\" onClick=\"createUser(this.form)\"/>
<input type=\"button\" name=\"backToLogin\" value=\"Log In\" onClick=\"writeLogin()\" />
</form>";
}
</script>
</head>
<body>
<a href="http://www.thatcompdude.com">ThatCompDude PHP Database Login</a>
<h1 class="pagetitle">Please enter your login information:</h1>
<div id="inputArea">
<form name="loginForm" id="loginForm" action="" method="post">
<h3>User: </h3><input type="text" name="user" />
<h3>Pass: </h3><input type="password" name="pass" />
<br/>
<INPUT TYPE="button" NAME="submitButton" Value="Submit" onClick="processLogin(this.form)">
<input type="button" value="Create Username" id="newUser" onClick="writeSignup()"/>
</form>
</div>
<div id="loginStatus"></div>
</body>
</html>
Does anyone have any answers to why this is not working?
The page running this code can be found at: http://drafts.thatcompdude.com/HaxMe/DatabaseAjaxLogin/ver2/
Another page without the signup form (that works) is at:
http://drafts.thatcompdude.com/HaxMe/DatabaseAjaxLogin/
The login for the pages is:
user: john_doe
pass:password
Thanks!
--Dylan