SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Git-R-Done
    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>
    Also, does anybody know what the javascript code is instead of using href="#"? I believe it's something along the lines of href="javascript;".
    John Saunders

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    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.

  3. #3
    Git-R-Done
    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

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •