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 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code problem with forms..

    I have a little snippet of code that works fine when I run it locally on my computer.When I upload it to my site it doesn't work. I cut and pasted the code directly from one file to the other. The only difference is that when the code is online it is within a bunch of other stuff. I am wondering if anybody could take a look at the source and tell me if theres anything obvious...

    this is in the body tag, right after <body>

    Code:
    <script  language="javascript">
    
     <!-- Begin
     function findEmailAddresses(StrObj) {
     var separateEmailsBy = "\n ";
     var email = "<none>"; // if no match, use this
     var emailsArray = StrObj.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
     if (emailsArray) {
     email = "";
     for (var i = 0; i < emailsArray.length; i++) {
     if (i != 0) email += separateEmailsBy;
     email += emailsArray[i];
           }
        }
     return email;
     }
     //  End -->
    </script>
    then later on I have this:

    Code:
    <form name='form'>
    <textarea name=comments rows=10 cols=50></textarea>
    
    <br>
    Emails in this documnet<br>
    <textarea name=email rows =10 cols=50></textarea>
    
    <BR><BR>
       <INPUT TYPE=button VALUE='Clear Data' NAME=button1 onclick=this.form.comments.value=''>
       <INPUT TYPE=button VALUE='Find Emails' NAME=button2 onclick=this.form.email.value=findEmailAddresses(this.value);>
    
    </form>
    the button that looks for email addresses does not work and I can't figure out why. Any idears??? Probably something simple...

    James

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by jwwceo View Post
    <INPUT TYPE=button VALUE='Find Emails' NAME=button2 onclick=this.form.email.value=findEmailAddresses(this.value);>
    </form>[/CODE]
    What data are you passing to the function?

  • #3
    New Coder
    Join Date
    Aug 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I pass through raw text files and it pulls out the emails only..... it works great on my local machine...that's why this is super bizarre...

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    when you refer to 'this.value' in the onclick for the button, 'this' is the button element, so you're passing "Find Emails" to the function. How it worked on your local computer I'm not sure...

  • #5
    New Coder
    Join Date
    Aug 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    think I know the problem now at least...

    whoops...that was my bad... I fixed that and pasted the wrong code...

    I found the actual problem though...this is wierd...

    I want only one email per line, so I changed this line:

    Code:
    var separateEmailsBy = ", ";
    to

    Code:
    var separateEmailsBy = "/n";
    it works on my home pute but not online. The only difference is that the online version is php page and when I tested it at home it was html. So maybe the php is not parcing that line break right.

    Is there a fix for this???

    JW


  •  

    Posting Permissions

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