Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-09-2006, 02:39 AM   PM User | #1
jwwceo
New Coder

 
Join Date: Aug 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
jwwceo is an unknown quantity at this point
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
jwwceo is offline   Reply With Quote
Old 11-09-2006, 02:53 PM   PM User | #2
Arty Effem
Banned

 
Join Date: May 2006
Location: England
Posts: 664
Thanks: 0
Thanked 84 Times in 84 Posts
Arty Effem can only hope to improve
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?
Arty Effem is offline   Reply With Quote
Old 11-09-2006, 03:00 PM   PM User | #3
jwwceo
New Coder

 
Join Date: Aug 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
jwwceo is an unknown quantity at this point
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...
jwwceo is offline   Reply With Quote
Old 11-09-2006, 04:20 PM   PM User | #4
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
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...
GJay is offline   Reply With Quote
Old 11-10-2006, 12:24 AM   PM User | #5
jwwceo
New Coder

 
Join Date: Aug 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
jwwceo is an unknown quantity at this point
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
jwwceo is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:36 AM.


Advertisement
Log in to turn off these ads.