Link to home
Create AccountLog in
Avatar of leapingleon
leapingleon

asked on

Registration form check if username already exists

Hi All

I want to register a new user, and check if the email they are entering already exists in the DB. This works perfectly in IE, but not at all in FX. The place where I found the code said it worked in both browsers, but only tested it now in FX, and cant seem to find where I found the code.

Any ideas?

Thanks

EDIT: With IE the popup comes up when an email exists, but with FX it just submits the form, even if I change it to return false at the end of the OnSubmit function. This is telling me that FX does not like something in the Javascript, but I dont know what.
<script language="javascript">
 
function OnSubmit(f) {
			
  checkUsername();
  
  if (document.getElementById("email_ok").value == 'no')
  {
	  alert("The email address you entered already exists. Please use another email address.");
	  document.getElementById("email").value = "";
	  document.getElementById("confirm_email").value = "";
	  document.getElementById("email_ok").value = "";
	  document.getElementById("email").focus();
	  return false;
  } 
	  
  return true;
  
}
 
function checkUsername()
{
      var username_field = document.getElementById("email");
 
      if (username_field.value == "")
      {
            username_field.focus();
      }
      else
      {
            xmlRequest = getXmlHttpObject();
 
            if (xmlRequest == null)
            {
                  // Browser does not support HTTP request
                  alert ("To use this feature, please upgrade to a current web browser");
            }
 
            var url = "Check_Email.php?username="+username_field.value;
 
            xmlRequest.onreadystatechange=stateChanged;
            xmlRequest.open("GET",url,true);
            xmlRequest.send(null);
      }
}
 
function stateChanged()
{
      // Only process if the response is complete
      if (xmlRequest.readyState==4 || xmlRequest.readyState=="complete")
      {
            var responseValue = parseInt(xmlRequest.responseText);
 
            if (responseValue == -1)
            {
                  alert("An error occured while checking your email. Please try again.");
            }
            else if (responseValue == 0)
            {
                  document.getElementById("email_ok").value = "yes";
            }
            else
            {
                  document.getElementById("email_ok").value = "no";
            }
      }
}
 
function getXmlHttpObject()
{
      var objXH=null;
      if (window.XMLHttpRequest)
      {
            objXH=new XMLHttpRequest();
      }
      else if (window.ActiveXObject)
      {
            objXH=new ActiveXObject("Microsoft.XMLHTTP");
      }
      return objXH;
}
 
</script>

Open in new window

Avatar of MacAnthony
MacAnthony
Flag of United States of America image

Sounds like it isn't either registering your onsubmit event or it isn't reading the email field value correctly. Is there a place to try this out or can you post the html? There doesn't appear to be anything that looks like it wouldn't work with the code that has been provided.
Avatar of leapingleon
leapingleon

ASKER

You can try it here if you want:

http://www.qa.business4sale.co.uk/Secure/Broker_Registration.php

username: qa
Password: password

Its a dev area, so you can fill in anything if you want. Fill it once with an address, and then try and re-register again with the same email. It works in IE, but not Firefox.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of MacAnthony
MacAnthony
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Tried that, still the same results.

Any other ideas?
Worked for me when I tested it on your site.
Now that is strange. It doesnt work for me.

Could it be different versions of FX, or something that I need to enable in FX for it to work. Im confused.

This could be a problem, if it only works for certain users, then it defeats the purpose because it only takes one user to enter a duplicate email.
could be a caching issue. you could try clearing cache and restarting the browser.