View Full Version : Code problem with forms..

11-09-2006, 03:39 AM
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>

<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 -->

then later on I have this:

<form name='form'>
<textarea name=comments rows=10 cols=50></textarea>

Emails in this documnet<br>
<textarea name=email rows =10 cols=50></textarea>

<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);>


the button that looks for email addresses does not work and I can't figure out why. Any idears??? Probably something simple...


Arty Effem
11-09-2006, 03:53 PM
<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?

11-09-2006, 04:00 PM
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...

11-09-2006, 05:20 PM
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...

11-10-2006, 01:24 AM
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:

var separateEmailsBy = ", ";


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???