PDA

View Full Version : Is it possible to get the content of textarea to send by email using JavaScript



PaulG2014
01-02-2015, 05:14 PM
Hi All,
I am trying to get the results of online exam to send by email following completion of test. I haven't a clue how to go about this and would welcome any advise that anyone can give me. The second issue is I can only get the correct answer to write to textarea and not the incorrect answers. My JavaScript code is:
function sayhello()
{
alert("hello");

}
var text2display = "";
var answers = new Array(10);
answers[0] = "1.This note is A#\n";
answers[1] = "2.This note is A\n";
answers[2] = "3.This note is B\n";
answers[3] = "4.This note is G\n";
answers[4] = "5.This note is D\n";
answers[5] = "6.This note is F#\n";
answers[6] = "7.This note is G#\n";
answers[7] = "8.This note is C\n";
answers[8] = "9.This note is E\n";
answers[9] = "10.This note is C#\n";
answers[10] = "11.This note is F\n";
answers[11] = "12.This note is D#\n";



var questions = new Array(10);
questions[0] = "q1";
questions[1] = "q2";
questions[2] = "q3";
questions[3] = "q4";
questions[4] = "q5";
questions[5] = "q6";
questions[6] = "q7";
questions[7] = "q8";
questions[8] = "q9";
questions[9] = "q10";


function checkQs(s)
{
var qs = document.getElementsByName(s);
var noOfRadios = qs.length;

for(var i = 0; i < noOfRadios; i++)
{
if(qs[i].checked)
{
if (qs[i].value == "correct")
text2display = text2display + questions[questions.indexOf(s)] + "...Well Done You are Correct\n";
else
text2diaplay = text2display + questions[questions.indexOf(s)] + "...Wrong Answer\n";

break;
}
}
}
function checkAll()
{
for(var i = 0; i < questions.length; i++)
{
checkQs(questions[i]);
{
testexam.answersBox.value = text2display;
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The Html code for sending is:

<input type ="button" value = "hello" onclick="sayhello()"></input>
<input type ="button" value = "submit" onclick ="checkAll()"></input>
<input type ="reset" value = "clear"></input>

<textarea rows ="6" cols = "60" name ="answersBox">Your Answer Results are Listed Below</textarea>

</form>
</body>
<footer>
<script type="text/javascript" src="js/testexam.js"></script>


</script>
</footer>