Javascript and Mailing and Forms, Oh My!

EdFred

Taxi to Parking
Joined
Feb 25, 2005
Messages
30,211
Location
Michigan
Display Name

Display name:
White Chocolate
Ok, so here's what I want to accomplish, and I have both parts done so far, I just need to figure out how to mesh them.

Part #1 -
bot e-mail dodger
ok , so it's not the best, but it goes like this:


<SCRIPT language=JavaScript>
<!--
function orderme(address, domain, subject, body) {
window.location.replace('mailto:'+address+'@'+domain+'?subject='+subject+'&body='+body);
}
-->
</script>

And then the e-mail link is:
<a href="javascript:eek:rderme()">email</a>

Part#2
I have a form that takes 8 fields and puts them into the body of an e-mail using

<FORM method=post action="mailto:address@domain?Subject=Purchase Order" enctype="text/plain">
<INPUT type=text name="from" size=26>
<INPUT type=text name="company" size=26>
...
...
<INPUT type="submit" value="Send Order">
</form>


What I want to do is merge the two so that my javascript body string gets all the form info written to it, so I don't have a "mailto:address@domain" hanging out there. I can't imagine it being too hard, but all my programming experience is just stealing from others, and then tweaking it a little bit, so I'm a bit stuck on how to mesh them.

Help me Obi-Wan!

 
Last edited:
Ok, I got it to work with one small problem

I can't get the \r or the \n in javascript to give me a carriage return or line feed when it writes to the e-mail. If I do an alert the CR and LF will work. But can't get it to transfer across to the e-mail.
 
dont know javascript all that well...
have you tried:
print '<br>';
or whatever the equlivelent to js would be?
 
That didn't work.
After looking at this for HOURS, and trying numerous things, I've come to the conclusion, that somehow I need this line:
<FORM method=post action="mailto:address@domain?Subject=Purchase Order" enctype="text/plain">
To be written in script to avoid spammers, but my attempts so far have failed.
 
To the original question, it wouldn't work in the chat becuase it kept converting it to HTML, but for the body to have the \n or the \r, you may want to try:

\n or \r

that would essentially be:
\n and \r

I'm just spitballing here.
 
SkyHog said:
To the original question, it wouldn't work in the chat becuase it kept converting it to HTML, but for the body to have the \n or the \r, you may want to try:

\n or \r

that would essentially be:
\n and \r

I'm just spitballing here.

if I do something like this:

function writeMessage() {
var Message = 'Write something\n'
Message = Message + 'Write another thing'
alert(Message)
}


I will get the alert box to say

Write something
Write another thing

but in the e-mail it writes it like

Write something\nWrite another thing

if I do a document.write(Message)
I get the same thing as I do with the e-mail

if I substitute <br> for the \n it comes out fine in the document.write
but in an e-mail it still just puts everything including the <br> on one line.
 
Just for the record, when posting in "advanced mode", if you want to post code samples:
Code:
the
   code tags;
           are
your
         friend
just wrap [ CODE ] and [/ CODE] around your code samples before posting. :)
 
Greebo said:
Just for the record, when posting in "advanced mode", if you want to post code samples:
Code:
the
   code tags;
           are
your
         friend
just wrap [ CODE ] and [/ CODE] around your code samples before posting. :)

doh! Ok - to EdFred:

Instead of \n or \r, try:
Code:
\n

or
\r

Hopefully, that doesn't convert :)

Bah - it did.

Lets try this:
Code:
\n

or

\r

ok - whew. I had to manually type the & codes for each letter to get that to work. Chuck - any chance of fixing the code tags?
 
Last edited:
N2212R said:
Ok, I got it to work with one small problem

I can't get the \r or the \n in javascript to give me a carriage return or line feed when it writes to the e-mail. If I do an alert the CR and LF will work. But can't get it to transfer across to the e-mail.
Ed can you post the script you've got so far inside of CODE tags so we can review where you are?

Its hard to say what to fix w/o being able to see the problem. :)
 
I found my way around the problem!
(but of course encountered another one)

with javascript, I simply called a new window in which the
Form Action is dynamically written using a string. It also allows them to "preview" their order. SO I got around the spam bots with that one...

however, now I am getting a 405 error when I run it over the web, so I need to figure out why the onclick="javascript:command(this.form)" is causing a page refresh with a 405 error.
 
this.form looks to me like it refers to an object or object collection, not a method.

But I'd need to see the whole source to be sure.
 
Chuck -

you can check out the script at


if you see the main site, you will see why I am rebuilding it.

from there go to "place order"
you will see what I've done to get around it.

but like I said, now I'm getting a 405 error. But not getting it on the main page with a similar form.
 
Last edited:
Ah, because you're using a submit button, and that triggers a form post, but the click method is calling your javascript.

Try using just:
HTML:
<INPUT type="button" value="Preview Order" onClick="javascript:sendorder(this.form)">
 
Greebo said:
Ah, because you're using a submit button, and that triggers a form post, but the click method is calling your javascript.

Woohoo!
I owe you lunch!
I still say I didn't do too bad of a job considering I have never messed with js before. Other than doing a window.open() command.
 
N2212R said:
Yikes! Love that ADIZ!
Nah,its not the ADIZs fault. Between alimony (which doesn't end until the end of 2006) and the increased car payment with my new car, the extra funds just haven't been there for flying. I love the new car but it pretty much doubled my car payment cause my old car, which I also loved, I got for a song by comparison.

*sigh* So in another year or so I'll be scheduling time with a CFI (unless I win the lottery and get to go up sooner) to polish off the rust. Until then, I'm not flying, just maintaining my club membership.
 
Back
Top