Connecting Tech Pros Worldwide Forums | Help | Site Map

My functions not working!!!

Member
 
Join Date: Feb 2007
Posts: 41
#1: Mar 5 '07
Hi, Can some one help me? I dont know why my checkEmail function is not working, it gives errors.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head><title>Registration Details</title>
  3. <SCRIPT LANGUAGE="JavaScript">
  4.  
  5.  
  6.  
  7. /**
  8.  
  9.  
  10. function processForm1() {
  11. var form1 = document.formOne;
  12.  if (form1.firstname.value==""){
  13.  alert("you must fill in your first name")
  14.  formOne.firstname.focus();
  15.  }
  16.  else if (form1.lastname.value==""){
  17.  alert("you must fill in your lastname")
  18.  formOne.lastname.focus();
  19.  }
  20.  else if (form1.postcode.value==""){
  21.  alert("you must fill in your postcode")
  22.  formOne.postcode.focus();
  23.  }
  24.  else if (form1.dateofbirth.value==""){
  25.  alert("you must fill in your DOB")
  26.  formOne.dateofbirth.focus();
  27.  }
  28.  else if (form1.contactphonenumber.value==""){
  29.  alert("you must fill in your phone number")
  30.  formOne.contactphonenumber.focus();
  31.  }
  32.  
  33.   else if (form1.emailaddress.value==""){
  34.  alert("you must fill in your email address")
  35.  formOne.emailaddress.focus();
  36.  }
  37.  
  38.  
  39.  
  40.  else { 
  41.     controlForm = parent.frame2.document.controlForm
  42.     controlForm.firstname.value=form1.firstname.value
  43.     controlForm.lastname.value=form1.lastname.value
  44.     controlForm.address.value=form1.address.value
  45.     controlForm.city.value=form1.city.value
  46.     controlForm.county.value=form1.county.value
  47.     controlForm.postcode.value=form1.postcode.value
  48.     controlForm.country.value=form1.country.value
  49.     controlForm.contactphonenumber.value=form1.contactphonenumber.value
  50.     controlForm.dateofbirth.value=form1.dateofbirth.value
  51.     controlForm.emailaddress.value=form1.emailaddress.value
  52.     controlForm.mypassword.value=form1.mypassword.value
  53.     location.href="login.html"
  54.  
  55. }
  56.  
  57. }**/
  58.  
  59. function checkEmail() {
  60. var emailFilter=/^/w+([/.-]?/w+)*@;
  61.   if(emailFilter.test(document.form1.emailaddress))
  62. return true
  63. else{
  64. alert(“invalid email address”)
  65.  formOne.emailaddress.focus();
  66. }
  67.  
  68.  }
  69.  
  70.  
  71.  
  72.  
  73. </script>
  74. </head>
  75.  
  76. <body>
  77. <form method="GET" action="http://localhost:8081/controlform.html" NAME="formOne"    >
  78.  
  79. <center>
  80. <h1>Registration Details</h1>
  81. <br><br>
  82. First Name <input type="text" name="firstname" value=""><br><br>
  83. Last Name <input type="text" name="lastname" value=""><br><br>
  84. Address <input type="text" name="address" value=""><br><br>
  85. City <input type="text" name="city" value=""><br><br>
  86. County (optional) <input type="text" name="county" value=""><br><br>
  87. Post Code <input type="text" name="postcode" value=""><br><br>
  88. Country <input type="text" name="country" value=""><br><br>
  89. Contact Phone Number <input type="text" name="contactphonenumber" value=""><br><br>
  90. Date of Birth <input type="text" name="dateofbirth" value=""><br><br>
  91. Email Address <input type="text" name="emailaddress" value=""><br><br>
  92. Password (minimum 6 characters) <INPUT TYPE=PASSWORD NAME="mypassword"><br><br>
  93. <input type="BUTTON" NAME="Submit"  value="--SUBMIT--" onClick="checkEmail()">
  94. </center>
  95. </form>
  96. </body>
  97. </html> 
  98.  
  99.  

iam_clint's Avatar
Forum Leader
 
Join Date: Jul 2006
Location: Oklahoma
Posts: 1,076
#2: Mar 5 '07

re: My functions not working!!!


if(emailFilter.test(document.form1.emailaddress))

needs to be

if(emailFilter.test(document.formOne.emailaddress) )


.test isn't anything so figure out what your problem is there


and your regular expression isn't declared as a regular expression.

and its not correct.
Member
 
Join Date: Feb 2007
Posts: 41
#3: Mar 5 '07

re: My functions not working!!!


ok, i have created the function checkemail2, and its also giving me errors.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head><title>Registration Details</title>
  3. <SCRIPT LANGUAGE="JavaScript">
  4.  
  5.  
  6.  
  7. /**
  8.  
  9.  
  10. function processForm1() {
  11. var form1 = document.formOne;
  12.  if (form1.firstname.value==""){
  13.  alert("you must fill in your first name")
  14.  formOne.firstname.focus();
  15.  }
  16.  else if (form1.lastname.value==""){
  17.  alert("you must fill in your lastname")
  18.  formOne.lastname.focus();
  19.  }
  20.  else if (form1.postcode.value==""){
  21.  alert("you must fill in your postcode")
  22.  formOne.postcode.focus();
  23.  }
  24.  else if (form1.dateofbirth.value==""){
  25.  alert("you must fill in your DOB")
  26.  formOne.dateofbirth.focus();
  27.  }
  28.  else if (form1.contactphonenumber.value==""){
  29.  alert("you must fill in your phone number")
  30.  formOne.contactphonenumber.focus();
  31.  }
  32.  
  33.   else if (form1.emailaddress.value==""){
  34.  alert("you must fill in your email address")
  35.  formOne.emailaddress.focus();
  36.  }
  37.  
  38.  
  39.  
  40.  else { 
  41.     controlForm = parent.frame2.document.controlForm
  42.     controlForm.firstname.value=form1.firstname.value
  43.     controlForm.lastname.value=form1.lastname.value
  44.     controlForm.address.value=form1.address.value
  45.     controlForm.city.value=form1.city.value
  46.     controlForm.county.value=form1.county.value
  47.     controlForm.postcode.value=form1.postcode.value
  48.     controlForm.country.value=form1.country.value
  49.     controlForm.contactphonenumber.value=form1.contactphonenumber.value
  50.     controlForm.dateofbirth.value=form1.dateofbirth.value
  51.     controlForm.emailaddress.value=form1.emailaddress.value
  52.     controlForm.mypassword.value=form1.mypassword.value
  53.     location.href="login.html"
  54.  
  55. }
  56.  
  57. }
  58.  
  59. function checkEmail() {
  60. var form1 = document.formOne;
  61. var emailFilter=/^/+w([/.-]?/+w)*@$/;
  62.   if(emailFilter.test(document.form1.emailaddress))
  63. return true
  64. else{
  65. alert(“invalid email address”)
  66.  formOne.emailaddress.focus();
  67. }
  68.  
  69.  }**/
  70.  
  71.  
  72.  function checkEmail2() {
  73.  var error = "";
  74.  var form1 = document.formOne;
  75.  var emailFilter=/^.+@.+\..{2,3,4,6}$/;
  76.  var email= form1.emailaddress.value;
  77. if (!(emailFilter.test(email)))  {
  78.        error = "Invalid email!\n";
  79.     }
  80. return error;   
  81.  }
  82.  
  83.  
  84. </script>
  85. </head>
  86.  
  87. <body>
  88. <form method="GET" action="http://localhost:8081/controlform.html" NAME="formOne"    >
  89.  
  90. <center>
  91. <h1>Registration Details</h1>
  92. <br><br>
  93. First Name <input type="text" name="firstname" value=""><br><br>
  94. Last Name <input type="text" name="lastname" value=""><br><br>
  95. Address <input type="text" name="address" value=""><br><br>
  96. City <input type="text" name="city" value=""><br><br>
  97. County (optional) <input type="text" name="county" value=""><br><br>
  98. Post Code <input type="text" name="postcode" value=""><br><br>
  99. Country <input type="text" name="country" value=""><br><br>
  100. Contact Phone Number <input type="text" name="contactphonenumber" value=""><br><br>
  101. Date of Birth <input type="text" name="dateofbirth" value=""><br><br>
  102. Email Address <input type="text" name="emailaddress" value=""><br><br>
  103. Password (minimum 6 characters) <INPUT TYPE=PASSWORD NAME="mypassword"><br><br>
  104. <input type="BUTTON" NAME="Submit"  value="--SUBMIT--" onClick="checkEmail2()">
  105. </center>
  106. </form>
  107. </body>
  108. </html> 
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Mar 5 '07

re: My functions not working!!!


See this page for info. on regular expressions. Your slashes are wrong and you haven't defined it properly.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#5: Mar 6 '07

re: My functions not working!!!


Aah, we both posted at the same time - didn't realise.

Again, I reiterate, your email regular expression is incorrect.

Try using something like:
Expand|Select|Wrap|Line Numbers
  1. /^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/
(adapted from the link I gave you).

Also, you have commented out all your functions!!
Reply