Javascript and mailto

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RobG

    #1

    Javascript and mailto


    I am trying to get users to fill in a form on a web page, then click a
    button to send an e-mail. I am using JavaScript to get the fields from
    the form, then run a mailto command to put the information into an
    email.

    I can create a mailto link in the page using innerHTML, but it seems
    silly to click a button, a link appears, then click on the link.

    How do I execute the mailto command using JavaScript?

    And before I get beaten up over using mailto, it's for a simple
    intranet application to get the answers to a couple of survey
    questions. I know all my users have one of two browsers and the same,
    fully configured e-mail client. The alternative is for some MS script
    guru to code the thing as a Word macro...yechh

    Some play code follows.

    Regards, Rob.

    <html><head><ti tle>Mail to page</title>
    <script type="text/javascript">
    function sendValues(f,x) {
    var a = f.elements;
    var b = "The message:";
    for (var i=0; i<a.length; i++) {
    if (a[i].parentNode.nod eName == 'LABEL'){
    if (a[i].type =='textarea' || a[i].type =='text')
    b += writeB(a[i]);
    if (a[i].type =='radio' && a[i].checked)
    b += writeB(a[i]);
    }
    }
    alert(b)
    alert(escape(b) );
    document.getEle mentById(x).inn erHTML = '<a href=\''
    + 'mailto:rob@mye mail.com?SUBJEC T=E-mail from a form'
    + '&body=' + escape(b) + '\'>Click here to send...</a>';
    }
    function writeB(x){
    return '\n' + x.name + ': ' + x.value;
    }
    </script>
    <style type="text/css">
    body {font-family: sans-serif; margin-left: 40;}
    input {font-family: sans-serif;}
    label {padding-bottom: 40;}
    </style>
    </head>
    <body margin>
    <form action="">
    <label for="a1">Enter text 1<br>
    <input type="text" name="a1"><br>
    <label for="a2">Enter text 2<br>
    <textarea name="a2" rows="5" cols="30"
    wrap="physical" ></textarea><br>
    <label for="a3">Pick an option
    <input type="radio" name="a3" value="none" checked="checke d"
    style="display: none;"><br>
    <input type="radio" name="a3" value="A">Optio n A<br>
    <input type="radio" name="a3" value="B">Optio n B<br>
    <input type="radio" name="a3" value="C">Optio n C<br>
    </label><br>
    <input type="reset" value="Clear all entries">&nbsp;
    <input type="button" value="Click to submit" onclick="
    sendValues(this .form,'xx');
    ">
    </form>
    <div id="xx"></div>
    </body>
    </html>
  • Fred Oz

    #2
    Re: Javascript and mailto

    RobG wrote:[color=blue]
    >
    > I am trying to get users to fill in a form on a web page, then click a
    > button to send an e-mail. I am using JavaScript to get the fields from
    > the form, then run a mailto command to put the information into an
    > email.[/color]

    As a quick note, Lotus Note seems to only allow a body of 200
    characters when using mailto - so keep your survey short!

    Fred.

    Comment

    • Hywel

      #3
      Re: Javascript and mailto

      In article <TAifd.139$I52. 5289@news.optus .net.au>, RobG says...[color=blue]
      >
      > I am trying to get users to fill in a form on a web page, then click a
      > button to send an e-mail. I am using JavaScript to get the fields from
      > the form, then run a mailto command to put the information into an
      > email.[/color]

      mailto: as a form action doesn't work. Use a server-side process. Read
      the links here:


      --
      Hywel


      Comment

      • RobG

        #4
        Re: Javascript and mailto

        Hywel wrote:[color=blue]
        > In article <TAifd.139$I52. 5289@news.optus .net.au>, RobG says...
        >[color=green]
        >> I am trying to get users to fill in a form on a web page, then click a
        >> button to send an e-mail. I am using JavaScript to get the fields from
        >> the form, then run a mailto command to put the information into an
        >> email.[/color]
        >
        >
        > mailto: as a form action doesn't work.[/color]

        I'm not trying to use it as a form action - see my play code.

        However, can you explain why the following works? I haven't tested it
        in IE with XP SP2, but it works in IE, Firefox, Safari...

        <form action="mailto: you@yourdmainhe re.com"
        method="post" enctype="text/plain">
        FirstName:<inpu t type="text" name="FirstName ">
        Email:<input type="text" name="Email">
        <input type="submit" name="submit" value="Submit">
        </form>

        [color=blue]
        > Use a server-side process. Read[/color]

        I've said I don't want to do that. This is for an intranet where the
        system admin nazis won't even let me see the security settings of IE:
        they are not going to let me setup a web server or use one of theirs.

        Perhaps I should have said a HTML page on a file server rather than a
        web page.
        [color=blue]
        > the links here:
        > http://www.allmyfaqs.com/faq.pl?Email_form_data
        >[/color]

        Great, but my play code does more than those links will teach you.
        Now, if I wanted to setup a server... :-)

        I want to do this for a very limited environment, it is not for the web
        or use beyond a team of about 20 people.

        Cheers, Rob.

        Comment

        • kaeli

          #5
          Re: Javascript and mailto

          In article <TAifd.139$I52. 5289@news.optus .net.au>, rgqld@iinet.net .auau
          enlightened us with...[color=blue]
          >
          > I am trying to get users to fill in a form on a web page, then click a
          > button to send an e-mail. I am using JavaScript to get the fields from
          > the form, then run a mailto command to put the information into an
          > email.
          >
          > I can create a mailto link in the page using innerHTML, but it seems
          > silly to click a button, a link appears, then click on the link.
          >
          > How do I execute the mailto command using JavaScript?
          >[/color]

          You don't.
          You've overcomplicatin g things.

          If you want the form fields to get mailed from a link click, just use mailto
          as the action of the form (like you did in your other post). Then, instead of
          a submit button, do
          <a href="javascrip t:document.form name.submit();" >Click to submit</a>

          The form fields will all get mailed. No other javascript required.

          Note that this is only for intranet apps, which you said yours was. There's a
          crapload wrong with it for internet use. :)

          --
          --
          ~kaeli~
          Frisbeetarianis m (n.), The belief that, when you die, your
          soul goes up on the roof and gets stuck there.



          Comment

          • Hywel

            #6
            Re: Javascript and mailto

            In article <417e0489$0$137 58$5a62ac22@per-qv1-newsreader-
            01.iinet.net.au >, RobG says...[color=blue]
            > Hywel wrote:[color=green]
            > > In article <TAifd.139$I52. 5289@news.optus .net.au>, RobG says...
            > >[color=darkred]
            > >> I am trying to get users to fill in a form on a web page, then click a
            > >> button to send an e-mail. I am using JavaScript to get the fields from
            > >> the form, then run a mailto command to put the information into an
            > >> email.[/color]
            > >
            > >
            > > mailto: as a form action doesn't work.[/color]
            >
            > I'm not trying to use it as a form action - see my play code.
            >
            > However, can you explain why the following works? I haven't tested it
            > in IE with XP SP2, but it works in IE, Firefox, Safari...
            >
            > <form action="mailto: you@yourdmainhe re.com"[/color]

            It doesn't. It works *for you*.


            [color=blue][color=green]
            > > Use a server-side process. Read[/color]
            >
            > I've said I don't want to do that. This is for an intranet where the
            > system admin nazis won't even let me see the security settings of IE:
            > they are not going to let me setup a web server or use one of theirs.[/color]

            Perhaps they'll also disable this functionality, too. Buy them cookies
            in return for them installing Apache. I'd be surprised if they haven't
            got a machine running IIS you could access. Offer them photos of things
            they won't normally see, such as trees or their wives/girlfriends
            nekkid.

            --
            Hywel


            Comment

            Working...