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

smitty62Asked:
Who is Participating?
 
NorieVBA ExpertCommented:
Shouldn't you be using getElementsByName or adding appropriate id attributes to your input elements?
0
 
leakim971PluritechnicianCommented:
you email client may not allow to run javascript which should be the case for security purpose
0
 
smitty62Author Commented:
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

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
smitty62Author Commented:
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

0
 
smitty62Author Commented:
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

0
 
smitty62Author Commented:
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.
0
 
smitty62Author Commented:
thank you for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.