Link to home
Start Free TrialLog in
Avatar of smitty62
smitty62Flag for United States of America

asked on

html generated email...body won't work.

The body of this email is not working.  What am I doing wrong?

Email: <input type="text" id="email"></input><br>
    Subject: <input type="text" id="subject"></input><br>
    Body: <input type="text" id="comment"></input><br>
    <button onclick="myFunction()">Review Before Sending</button>

    <p id="demo"></p>

    <script>
      function myFunction() {
        var input = document.getElementById('email');
        email = input.value;
        var input = document.getElementById('subject');
        subject = input.value;
		var input = document.getElementById('comment');
        subject = input.value;

        window.location.href = "mailto:" + email + "?subject=" + subject + "&body=" + comment;
      }
    </script>

Open in new window

Avatar of leakim971
leakim971
Flag of Guadeloupe image

you email client may not allow to run javascript which should be the case for security purpose
Avatar of smitty62

ASKER

The code below works, but I need to get the body (input fields)  inserted. How do I create a string field variable then use that variable in the "action=" option.

<form style="text-align:left; margin:5%"  action="mailto:doi.webmaster@illinois.gov?subject=Test_Mail" method="post" enctype="text/plain">
Name: <input type="text" name="name"><br>
org: <input type="text" name="org"><br>
Comment: <input type="text" name="comment" size="50"><br><br>
<input type="text" name="string"><br>
<input type="submit" value="Send"> <input type="reset" value="Reset">
</form>

Open in new window

okay, I've been working on this, and so far this is what I have, however the variable is not be recognized by the "action="

I've seen other code snippets out there using a variable in this way, but I can't get it to work.

<form style="text-align:left; margin:5%"  action="stringer" method="post" enctype="text/plain">
Name: <input type="text" name="name"><br>
Organization: <input type="text" name="org"><br>
Comment: <input type="text" name="comment" size="50"><br><br>
<input type="text" name="string"><br>
<input type="submit" value="Send"> <input type="reset" value="Reset">
</form>

<script>
				      function myFunction() {
						var input = document.getElementById('name');
				        email = input.value;
				        var input = document.getElementById('org');
				        subject = input.value;
					    var input = document.getElementById('comment');
				        subject = input.value;
					    var stringer = "mailto:doi.webmaster@illinois.gov?subject=Test_Mail&body=" + name + " - " + org + " - " + comment;
      				  }
    			    </script>

Open in new window

This is working, however a null is getting inserted into the variables for some reason.

 <script type="text/javascript">
				      function myFunction() {
						alert("alert message1");
						var name1 = document.getElementById('name');
						alert(name1);
				        var org1 = document.getElementById('org');
						alert(org1);
					    var comment1 = document.getElementById('comment');
						alert(comment1);
					    window.location.href = "mailto:doi.webmaster@illinois.gov?subject=Test_Mail&body=" + name1 + " - " + org1 + " - " + comment1;
      				  }
    			    </script>

Open in new window


<form style="text-align:left; margin:5%"  action="stringer" method="post" enctype="text/plain">
Name: <input type="text" name="name"><br>
Organization: <input type="text" name="org"><br>
Comment: <input type="text" name="comment" size="50"><br><br>
<button onClick="myFunction()">Review your comment</button>
<!-- <input type="submit" value="Send"> <input type="reset" value="Reset"> -->
</form>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think your right about that.  I think that's for .net not html.  I was hoping to use fill in boxes then setup in a form, then with javascipt move that information in to the href mailto: statement using a variable, however, the user decided on something else and we will be using survey monkey to collect the data instead.

Thank you for help.
thank you for your help.