Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    add domain on onBlur of email form

    Hi. Does anyone know how to automatically add the domain name at the end of an email address field? What im looking for is a script that checks the email address a user enters and if they type their full email (ex: frank@email.com) it would just do nothing, but if they only enter their username (ex: frank), it would automatically add the "@email.com" part when they click out of the email field. I've tried modifying a few other scripts i found online but I can't seem to make it work. If anyone knows how to do this I would greatly appreciate some help. If the description needs to be clearer please let me know. thanks!

  • #2
    zfs
    zfs is offline
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That should do it:
    Code:
    <script type="text/javascript">
      function append_domain(domain) {
        var f = document.getElementById('email');
        var spl = f.value.split('@');
        if (spl.length == 1)
            f.value += '@' + domain;
      }
    </script>
    
    <input id="email" name="email" value="" onblur="append_domain('email.com');">
    I assumed that you always want to append the same domain name (email.com) if it is not specified.

    PS. Don't forget to set id (marked red) to your input field!

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    WORKS!! thanks 100000000000%. Very fast reply too.

    I know i didnt mention this in the original post (just thought of it) but is there a way to make it so that if the user focuses on the email field but doesn't type anything it will stay blank when they click out of it? Thanks again.

  • #4
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,387
    Thanks
    32
    Thanked 288 Times in 282 Posts
    You can probably do that by changing the line

    Code:
    if (spl.length == 1)
    to

    Code:
    if (f.value && spl.length == 1)
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #5
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    glennt:

    Code:
    <label>Email: <input type='text' name='email' size='15' onblur="/\@|^.{0,0}$/g.test(this.value) ? '' : this.value +='@email.com'"></label>

  • #6
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sweet! thanks guys


  •  

    Posting Permissions

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