Have been scratching my head over this for an hour or so. I have a dynamic check that will tell the user registering if the username they have entered is already being used (before they submit the form). However, I cannot at all get it to run the Javascript function I have written. Any suggestions would be great. Here is the HTML form:
Code: Select all
<html>
<head>
<script type="text/javascript" src="scripts/formAjax.js"></script>
<title>Register</title>
</head>
<body onLoad="generateAuthToken();">
<form method="POST" action="functions/addUser.php" name="frmRegister" >
Username:<input type="text" name="strUsername" maxlength="15" size="20" onkeyup="checkUsername(this.value)" /><span id="strCheckResult">Check here</span><br />
Display Name:<input type="text" name="strDisplayName" maxlength="15" size="20" /><br />
Email:<input type="text" name="strEmail" /><br />
Password:<input type="password" name="strPassword" /><br />
Confirm Password:<input type="password" name="strPasswordConfirm" /><br />
Please enter the text below:<input type="text" name="strCaptcha" maxlength="6" /><br />
<img src="functions/createCaptcha.php" border="0" /><br />
<input type="hidden" name="formToken" value="" /><br />
<input type="submit" name="registerUser" value="Register" />
</form>
</body>
</html>
This fails to call the function within the external JS file. Here is the JS function:
Code: Select all
//Check username isn't taken
function checkUsername(str)
{
xmlHTTP = GetXmlHttpObject();
if (xmlHTTP == null)
{
return;
}
var requestURL = "includes/checkUsername.php";
requestURL = requestURL + "?usr=" + str;
requestURL = requestURL + "?sid=" + Math.random();
xmlHTTP.onreadystatechange = function()
{
if(xmlHTTP.readyState == 4)
{
document.getElementById("strCheckResult").innerHTML = xmlHTTP.responseText;
}
}
xmlHTTP.open("GET", url, true);
xmlHTTP.send(null);
}