SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Feb 26, 2003, 11:41 #1
- Join Date
- Nov 2001
- Posts
- 1,194
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How Can I Turn This into One Function?
I have the following functions and I need to make them so they are just run under one function. Can somebody tell me how to do this? The only one that works is the check e-mail, then the other two do not work once I hit submit after typing in a valid e-mail address. If I remove the check e-mail function, it submits properly.
Code:function validEmail(email) { invalidChars = " /:,;" // cannot be empty if (email == "" ) { return false } // does it contain any invalid characters? for (i=0; i<invalidChars.length; i++) { badChar = invalidChars.charAt(i) if (email.indexOf(badChar,0) > -1) { return false } } // there must be one "@" symbol atPos = email.indexOf("@",1) if (atPos == -1) { return false } // and only one "@" symbol if (email.indexOf("@",atPos+1) != -1) { return false } // and at least one "." after the "@" periodPos = email.indexOf(".",atPos) if (periodPos == -1) { return false } // must be at least 2 characters after the "." if (periodPos+3 > email.length) { return false } return true } // run the validEmail function function checkAddress(inputStr) { var mailValue = inputStr.value if (!validEmail(mailValue)) { alert("Please enter a valid email address" ) inputStr.focus() inputStr.select() return false } else { return true } } function submit1() { document.ccoptin.action = "script.asp" document.ccoptin.target = "_blank" document.ccoptin.submit(); } function submit2() { document.ccoptin.action = "script2.asp" document.ccoptin.target = "" document.ccoptin.submit(); } <form name="ccoptin" method="post"> <input type="text" name="ea" value="Type e-mail here" size="15" onClick="this.value=''"> <a href="#" onClick="return checkAddress(ea);submit1();submit2()"> </form>
John Saunders
-
Feb 26, 2003, 15:07 #2
- Join Date
- Dec 2002
- Location
- Alabama, USA
- Posts
- 2,560
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi John,
Your question is not the problem I see. I don't think you can issue two form submissions like that. I'm not sure... but I'm sure some of the other members know the answer.
-
Feb 26, 2003, 15:26 #3
- Join Date
- Nov 2001
- Posts
- 1,194
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for your response. I know it may not be "proper" but I'm positive it works cause that's what I've been using for a while. The problem is that people are just clicking submit and it is being processed without a valid e-mail address.
If you or anybody has any suggestions as to how I can do these three steps (the first one then if it's valid process the second and third ones), I woud appreciate it.John Saunders
-
Feb 26, 2003, 19:47 #4
- Join Date
- Dec 2002
- Location
- Alabama, USA
- Posts
- 2,560
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi John,
The only changes I made are to the following. Am I getting close?
Code:function checkAddress(inputStr) { var mailValue = inputStr.value if (!validEmail(mailValue)) { alert("Please enter a valid email address" ) inputStr.focus() inputStr.select() } else { submit1(); submit2(); } } <form name="ccoptin" method="post"> <input type="text" name="ea" value="Type e-mail here" size="15" onClick="this.value=''"> <a href="javascript: checkAddress(ea)">Submit</a> </form>
Bookmarks