email, zipcode, and password confirm problem

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Apr 2004
Posts: 59
Reputation: world_weapon is an unknown quantity at this point 
Solved Threads: 2
world_weapon's Avatar
world_weapon world_weapon is offline Offline
Junior Poster in Training

email, zipcode, and password confirm problem

 
0
  #1
Sep 22nd, 2007
Brief overview, have three functions that return boolean for the zip code and email format and another to check if two fields are not empty and contain the same value. The wrapper functions I made that use another function to write to a div.innerHTML work fine. The function I made to check them all and then to call the 3 individual wrapper functions doesnt respond at all. FF Error Console reports nothing and IE does not alert anything either. I don't know what is wrong. If anyone can take a look at the code and tell me where I am doing something wrong or try to run it in your own browser? Any help is very much appreciated.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <title>Test Form Checker</title>
  5. <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  6. <meta name="generator" content="HAPedit 3.1">
  7. <script type="text/javascript">
  8. function isValidZip(value) {
  9. var re = /^\d{5}([\-]\d{4})?$/;
  10. return (re.test(value));
  11. }
  12.  
  13. function validEmail(str){
  14. return ((str.indexOf(".",str.indexOf("@")) - str.indexOf("@") > 1) && (str.indexOf("@") == str.lastIndexOf("@")) && (str.indexOf("@") > 0 && str.lastIndexOf(".") < str.length - 1))
  15. }
  16.  
  17. function isPassword(x,y) {
  18. return (x != "" && x == y)
  19. }
  20.  
  21. function writeTo(x){
  22. M = document.getElementById("dumpHere");
  23. M.innerHTML+=x+"<br />"
  24. return true;
  25. }
  26.  
  27. function testZip(v) {
  28. if (isValidZip(v)){
  29. writeTo("Valid Zip Code Format!");
  30. return true;
  31. }
  32. writeTo("Not a valid zip code format!!!");
  33. return true;
  34. }
  35.  
  36. function testEmail(v){
  37. if (validEmail(v)){
  38. writeTo("Valid E-mail Format");
  39. return true;
  40. }
  41. writeTo("Not valid email format!!!");
  42. return false;
  43. }
  44.  
  45. function checkPass(){
  46. if (isPassword(document.getElementById("input3").value,document.getElementById("input4").value)){
  47. writeTo("Password Good!!!!");
  48. return true
  49. }
  50. writeTo("Password not valid, enter a value and matching value to confirm!!!")
  51. return true
  52. }
  53.  
  54. function testForm() {
  55. if (validEmail(document.getElementById("input2").value) && isValidZip(document.getElementById("input1").value) && isPassword(document.getElementById("input3").value,document.getElementById("input4").value)){
  56. writeTo("Form Ready to Submit!!!");
  57. return true;
  58. }
  59. isValidZip(document.getElementById('input1').value);
  60. isValidEmail(document.getElementById('input2').value);
  61. checkPass();
  62. return true
  63. }
  64. </script>
  65. </head>
  66. <body bgcolor="#FFFFFF">
  67. <hr />
  68. <input type="text" id="input1"><br />
  69. <input type="text" id="input2"><br />
  70. <input type="text" id="input3"><br />
  71. <input type="text" id="input4"><br />
  72. <input type="button" value="Is Input1 zipcode?" onclick="testZip(document.getElementById('input1').value);"><br />
  73. <input type="button" value="Is Input2 email?" onclick="testEmail(document.getElementById('input2').value);"><br />
  74. <input type="button" value="Is Input3 and Input4 same?" onclick="checkPass();"><br />
  75. <input type="button" value="Check" onlick="testForm()"><br />
  76. <div id="dumpHere"></div>
  77. </body>
  78. </html>
I wish I that I would get an error or something, but this literally shows me nothing. Maybe someone here can identify where I went wrong with it.
The purpose of my existence is why I am here.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 59
Reputation: world_weapon is an unknown quantity at this point 
Solved Threads: 2
world_weapon's Avatar
world_weapon world_weapon is offline Offline
Junior Poster in Training

Re: email, zipcode, and password confirm problem

 
0
  #2
Sep 22nd, 2007
Ok, I think I typoed on the
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function testForm() {
  2. if (validEmail(document.getElementById("input2").value) && isValidZip(document.getElementById("input1").value) && isPassword(document.getElementById("input3").value,document.getElementById("input4").value)){
with ))
The purpose of my existence is why I am here.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 59
Reputation: world_weapon is an unknown quantity at this point 
Solved Threads: 2
world_weapon's Avatar
world_weapon world_weapon is offline Offline
Junior Poster in Training

Re: email, zipcode, and password confirm problem

 
0
  #3
Sep 22nd, 2007
No that has to be there, otherwise there is an error. Darn, I can't figure it out. Someone please help.
The purpose of my existence is why I am here.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 59
Reputation: world_weapon is an unknown quantity at this point 
Solved Threads: 2
world_weapon's Avatar
world_weapon world_weapon is offline Offline
Junior Poster in Training

Re: email, zipcode, and password confirm problem

 
0
  #4
Sep 22nd, 2007
Ok, the code I posted earlier was calling the wrong functions, but I fixed that, I even removed the if statement from testForm() This is what I am currently running but the effect is still the same for me, no response and no error. Its funny but the error console should have flagged the wrong function name in the earlier code, but I don't know what is going on here.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <title>Test Form Checker</title>
  5. <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  6. <meta name="generator" content="HAPedit 3.1">
  7. <script type="text/javascript">
  8. function isValidZip(value) {
  9. var re = /^\d{5}([\-]\d{4})?$/;
  10. return (re.test(value));
  11. }
  12.  
  13. function validEmail(str){
  14. return ((str.indexOf(".",str.indexOf("@")) - str.indexOf("@") > 1) && (str.indexOf("@") == str.lastIndexOf("@")) && (str.indexOf("@") > 0 && str.lastIndexOf(".") < str.length - 1));
  15. }
  16.  
  17. function isPassword(x,y) {
  18. return (x != "" && x == y);
  19. }
  20.  
  21. function writeTo(x){
  22. M = document.getElementById("dumpHere");
  23. M.innerHTML+=x+"<br />";
  24. return true;
  25. }
  26.  
  27. function testZip(v) {
  28. if (isValidZip(v)){
  29. writeTo("Valid Zip Code Format!");
  30. return true;
  31. }
  32. writeTo("Not a valid zip code format!!!");
  33. return true;
  34. }
  35.  
  36. function testEmail(v){
  37. if (validEmail(v)){
  38. writeTo("Valid E-mail Format");
  39. return true;
  40. }
  41. writeTo("Not valid email format!!!");
  42. return false;
  43. }
  44.  
  45. function checkPass(){
  46. if (isPassword(document.getElementById("input3").value,document.getElementById("input4").value)){
  47. writeTo("Password Good!!!!");
  48. return true;
  49. }
  50. writeTo("Password not valid, enter a value and matching value to confirm!!!");
  51. return true;
  52. }
  53.  
  54. function testForm() {
  55. testZip(document.getElementById('input1').value);
  56. testEmail(document.getElementById('input2').value);
  57. checkPass();
  58. return true;
  59. }
  60. </script>
  61. </head>
  62. <body bgcolor="#FFFFFF">
  63. <hr />
  64. <input type="text" id="input1"><br />
  65. <input type="text" id="input2"><br />
  66. <input type="text" id="input3"><br />
  67. <input type="text" id="input4"><br />
  68. <input type="button" value="Is Input1 zipcode?" onclick="testZip(document.getElementById('input1').value);"><br />
  69. <input type="button" value="Is Input2 email?" onclick="testEmail(document.getElementById('input2').value);"><br />
  70. <input type="button" value="Is Input3 and Input4 same?" onclick="checkPass();"><br />
  71. <input type="button" value="Check" onlick="testForm();"><br />
  72. <div id="dumpHere"></div>
  73. </body>
  74. </html>
The purpose of my existence is why I am here.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,203
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 164
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: email, zipcode, and password confirm problem

 
0
  #5
Sep 22nd, 2007
You have a < character in your script.

You have to have a separate .js file when this happens. Otherwise, HTML parsing begins again at the < character.

Also, anyone can read your code and find out the password. You must use server-side processing (not client-side) for passwords.
Last edited by MidiMagic; Sep 22nd, 2007 at 10:08 pm.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 59
Reputation: world_weapon is an unknown quantity at this point 
Solved Threads: 2
world_weapon's Avatar
world_weapon world_weapon is offline Offline
Junior Poster in Training

Re: email, zipcode, and password confirm problem

 
0
  #6
Sep 22nd, 2007
Thanks for the lead, I am currently looking for that character in the script, and this is just the register new page, these functions will actually just check the form before posting to itself and it is in php. This was just a dummy page to check the functionality.
I am still going to have php check things again as well as check for the username already in the database, among other things. Hopefully I can find the < char. Hopefully this will fix things and I can use the functions. I just didnt want the php to process it over and over again, and figured that having javascript precheck it would reduce the amount of times the server would possibly do it. Yeah I know that having javascript check the form and then php again is a bit redundant, but at least my server doesnt have to serve the page again and again over silly mistakes.
The purpose of my existence is why I am here.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 59
Reputation: world_weapon is an unknown quantity at this point 
Solved Threads: 2
world_weapon's Avatar
world_weapon world_weapon is offline Offline
Junior Poster in Training

Re: email, zipcode, and password confirm problem

 
0
  #7
Sep 22nd, 2007
Hmmm, I found the < char in the validEmail() function as checking to make sure that a period was not the last char in the string and again in a string in the writeTo() function that I use to write to the div and add a line break. I will try these in an external script. Maybe that will make them work. I'll post again after the test.
The purpose of my existence is why I am here.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 59
Reputation: world_weapon is an unknown quantity at this point 
Solved Threads: 2
world_weapon's Avatar
world_weapon world_weapon is offline Offline
Junior Poster in Training

Re: email, zipcode, and password confirm problem

 
0
  #8
Sep 22nd, 2007
Well, I tried first to change the validEmail() function and the writeTo() function without the < character and so I did. The problem still persist. The 3 buttons calling the individual wrapper functions work but the button that calls them one after another does not. I tried also putting the functions in the external .js and that did not work either. The code still works for the first three
buttons meaning that the functions are working, but why would the testForm() not work. Im still lost. This is the working code with the <'s taken out.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <title>Test Form Checker</title>
  5. <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  6. <meta name="generator" content="HAPedit 3.1">
  7. <script type="text/javascript">
  8. function isValidZip(value) {
  9. var re = /^\d{5}([\-]\d{4})?$/;
  10. return (re.test(value));
  11. }
  12.  
  13. function validEmail(str){
  14. return ((str.indexOf(".",str.indexOf("@")) - str.indexOf("@") > 1) && (str.indexOf("@") == str.lastIndexOf("@")) && (str.indexOf("@") > 0 && str.length - 1 > str.lastIndexOf(".")));
  15. }
  16.  
  17. function isPassword(x,y) {
  18. return (x != "" && x == y);
  19. }
  20.  
  21. function writeTo(x){
  22. M = document.getElementById("dumpHere");
  23. M.innerHTML+=x+"&lt;br />";
  24. return true;
  25. }
  26.  
  27. function testZip(v) {
  28. if (isValidZip(v)){
  29. writeTo("Valid Zip Code Format!");
  30. return true;
  31. }
  32. writeTo("Not a valid zip code format!!!");
  33. return true;
  34. }
  35.  
  36. function testEmail(v){
  37. if (validEmail(v)){
  38. writeTo("Valid E-mail Format");
  39. return true;
  40. }
  41. writeTo("Not valid email format!!!");
  42. return false;
  43. }
  44.  
  45. function checkPass(){
  46. if (isPassword(document.getElementById("input3").value,document.getElementById("input4").value)){
  47. writeTo("Password Good!!!!");
  48. return true;
  49. }
  50. writeTo("Password not valid, enter a value and matching value to confirm!!!");
  51. return true;
  52. }
  53.  
  54. function testForm() {
  55. testZip(document.getElementById('input1').value);
  56. testEmail(document.getElementById('input2').value);
  57. checkPass();
  58. return true;
  59. }
  60. </script>
  61. </head>
  62. <body bgcolor="#FFFFFF">
  63. <hr />
  64. <input type="text" id="input1"><br />
  65. <input type="text" id="input2"><br />
  66. <input type="text" id="input3"><br />
  67. <input type="text" id="input4"><br />
  68. <input type="button" value="Is Input1 zipcode?" onclick="testZip(document.getElementById('input1').value);"><br />
  69. <input type="button" value="Is Input2 email?" onclick="testEmail(document.getElementById('input2').value);"><br />
  70. <input type="button" value="Is Input3 and Input4 same?" onclick="checkPass();"><br />
  71. <input type="button" value="Check" onlick="testForm();"><br />
  72. <div id="dumpHere"></div>
  73. </body>
  74. </html>
The wrapper functions use the wrtieTo() and now print out the br tags as text instead of the actual line breaks, and the functions still work although the text doesnt have line breaks, but what I can't figure out is why the testForm() still doesnt work.
Last edited by world_weapon; Sep 22nd, 2007 at 11:43 pm. Reason: Misprint
The purpose of my existence is why I am here.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,203
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 164
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: email, zipcode, and password confirm problem

 
0
  #9
Sep 23rd, 2007
What I saw was in the function "writeTo". It doesn't matter if the character is inside quotes.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,203
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 164
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: email, zipcode, and password confirm problem

 
0
  #10
Sep 23rd, 2007
Parameter passing does not work in the normal way when you use onclick or some other on- call. You can't put a parameter inside the function call parentheses in the way you do in javascript itself.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC