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

>> Line 9 - It should be document.loginForm.user.value
>> Line 10 - It should be document.loginForm.pass.value
>> Line 24 - The request is not yet ready. Use the following:

xmlhttp.onreadystatechange=function() {
 if ( (xmlhttp.readyState == 4) && (xmlhttp.status == 200) ) {
document.getElementById('loginStatus').innerHTML=xmlhttp.responseText;
}
}

~G

>> Line 9 - It should be document.loginForm.user.value
>> Line 10 - It should be document.loginForm.pass.value
>> Line 24 - The request is not yet ready. Use the following:

xmlhttp.onreadystatechange=function() {
if ( (xmlhttp.readyState == 4) && (xmlhttp.status == 200) ) {
document.getElementById('loginStatus').innerHTML=xmlhttp.responseText;
}
}

xmlhttp.onreadystatechange=function() { if ( (xmlhttp.readyState == 4) && (xmlhttp.status == 200) ) { document.getElementById('loginStatus').innerHTML=xmlhttp.responseText; } }

~G

Acatually, you dont need document in front of the form. The form is being passed to the function from within the form, so the hierarchy stays from within the form. To the code, the form is the 'document' from which it is operating in. Also, this did not work in the code anyway. I just want to change the form, and I think I will change my scope from writing my own code to trying a lib like jQuery or Mootools.

Thanks anyway! And if anyone has some idea of how to do this with jQuery, please do tell!
--Dylan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.