Advertisement

03.06.2008 at 02:07AM PST, ID: 23218955
[x]
Attachment Details

Registration form check if username already exists

Asked by leapingleon in JavaScript

Tags: Javascript, AJAX

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.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
<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>
[+][-]03.06.2008 at 06:42AM PST, ID: 21060568

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.06.2008 at 07:54AM PST, ID: 21061442

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.06.2008 at 08:14AM PST, ID: 21061719

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: Javascript, AJAX
Sign Up Now!
Solution Provided By: MacAnthony
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.06.2008 at 08:33AM PST, ID: 21061958

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.06.2008 at 08:53AM PST, ID: 21062209

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.06.2008 at 08:57AM PST, ID: 21062264

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.06.2008 at 09:13AM PST, ID: 21062467

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.06.2008 at 09:19AM PST, ID: 21062531

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628