Forum Moderators: open
Ok, well, I am creating an iq test website and need some help on how to get the alert message with the score to come up, with it emailing the score to me.
Here's some of the source code for the quiz:
In the header...
<script language="JavaScript">
function tester() {
var a = 0
var b = 0
var c = 0
var d = 0
if(document.forms[0].elements[1].checked==true) {
a = 1
}
if(document.forms[0].elements[4].checked==true) {
b = 1
}
if(document.forms[0].elements[11].checked==true) {
c = 1
}
total = a + b + c + d
score = 100*total
if (total==0){
alert("Your score was 0...were you even trying?")
}
if (total > 0){
alert("Your score is "+ score +"! Great Job!")
}
}
</script>
<form method="get" onsubmit="tester()">
1. Which number doesn't belong?
<p><input type="radio" name="R1" value="V1">714 </p>
<p><input type="radio" name="R1" value="V2">892 </p>
<p><input type="radio" name="R1" value="V3">993 </p>
<p><input type="radio" name="R1" value="V4">698 </p>
<div align="center"><center><p><input type="submit" value="Get Score"></p>
</center></div>
Currently, this only comes up with an alert box which says the score...but is there any way to make it still do that, and also email the score to me, all by pressing the submit?
Thanks in advance.
<form method=yest action=myscript.cgi>
The file "myscript.cgi" is a Perl or PHP program you wrote and uploaded to the server. That program displays the results to the user and then emails you the results. Perl and PHP are not hard to learn and it's worth learning one of them, especially if you want to do things like send emails or store info in a database.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function sendMail(_frm){
var eml="you@youraddress.com";
var bod="&body="+_frm.selOne.value+" ¦¦ "+_frm.txtOne.value;
var subj="?subject=Whatever you want";
location.href="mailto:"+eml+subj+bod;
}
</script>
</head>
<body>
<form action="mailto:you@youraddress.com" enctype="text/plain"
method="POST" onsubmit="sendMail(this);return false;">
<select name="selOne">
<option value="Dog">Dog</option>
<option value="Cat">Cat</option>
</select>
<textarea name="txtOne"></textarea>
<input type="submit" value="Submit" />
</form>
</body>
</html>
The other downside is that Javascript-dependent solutions require that the user has Javascript turned on. Most do, but some turn it off because it's the best way to block popup windows (since popups depend on Javascript).
Also, the script just calls up a new email message, it doesn't actually send. You're relying on the user to actually click Send, and maybe they won't.
If you link your <FORM> to a PHP or Perl script then you can avoid all three downsides.