Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Results of Quiz

Status
Not open for further replies.

sammysmith

Technical User
Apr 27, 2005
2
US
I have used some scripts before, but I do not know how to program javascript or don't understand the code.

I am using a Quiz script provided at It uses the following three elements.
-popquiz.htm (Edit this file to change the questions on the page to your own. View source for more information)
-results.htm (Page containing the results/grades. Not necessary to edit)
-quizconfig.js (Edit this file to change the solutions to your own)

This quiz script works great.

My question:
The results page displays the quiz takers percentage score, questions wrong, and number of questions right. Can the information provided on the results page be emailed to an email address input by the quiz taker? Similiar to email a friend script.

If so, can anyone help me out the the proper script?

If you would like to see how I use the script, visit:
Some code below.

Thank you in advance for your help.


--------RESULTS Page Scripts----------
<script src="quizconfig.js">
</script>

<script>
var actualchoices=new Array()
document.cookie="ready=yes"
</script>
</head>
<body bgcolor="#ffffff" marginwidth="0" marginheight="0" topmargin="0" leftmargin="0">
<!--webbot bot="HTMLMarkup" startspan -->
<script language="JavaScript">
<!-- hide this script from non-javascript-enabled browsers

if (document.images) {
PhilMain_r01_c3_F1 = new Image(153,29); PhilMain_r01_c3_F1.src = "../Images/PhilMain_r01_c3.gif";
PhilMain_r01_c3_F2 = new Image(153,29); PhilMain_r01_c3_F2.src = "../Images/PhilMain_r12_c1_F2.gif";
PhilMain_r12_c1_F3 = new Image(140,16); PhilMain_r12_c1_F3.src = "../Images/PhilMain_r12_c1_F3.gif";
}

/* function that swaps images */

function di20(id, newSrc) {
var theImage = FWFindImage(document, id, 0);
if (theImage) {
theImage.src = newSrc;
}
}


function FWFindImage(doc, name, j) {
var theImage = false;
if (doc.images) {
theImage = doc.images[name];
}
if (theImage) {
return theImage;
}
if (doc.layers) {
for (j = 0; j < doc.layers.length; j++) {
theImage = FWFindImage(doc.layers[j].document, name, 0);
if (theImage) {
return (theImage);
}
}
}
return (false);
}


function setCookie(name, value) {
document.cookie = name + "=" + escape(value);
}

function getCookie(Name) {
var search = Name + "=";
var retVal = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search);
if (offset != -1) {
end = document.cookie.indexOf(";", offset);
offset += search.length;
if (end == -1) {
end = document.cookie.length;
}
retVal = unescape(document.cookie.substring(offset, end));
}
}
return (retVal);
}

function InitGrp(grp) {
var cmd = false;
if (getCookie) {
cmd = getCookie(grp);
}
if (cmd) {
eval("GrpDown(" + cmd + ")");
eval("GrpRestore(" + cmd + ")");
}
}

function FindGroup(grp, imageName) {
var img = FWFindImage(document, imageName, 0);
if (!img) {
return (false);
}
var docGroup = eval("document.FWG_" + grp);
if (!docGroup) {
docGroup = new Object();
eval("document.FWG_" + grp + " = docGroup");
docGroup.theImages = new Array();
}
if (img) {
var i;
for (i = 0; i < docGroup.theImages.length; i++) {
if (docGroup.theImages == img) {
break;
}
}
docGroup.theImages = img;
if (!img.atRestSrc) {
img.atRestSrc = img.src;
img.initialSrc = img.src;
}
}
return (docGroup);
}

function GrpDown(grp, imageName, downSrc, downOver) {
if (!downOver) {
downOver = downSrc;
}
var cmd = "'" + grp + "','" + imageName + "','" + downSrc + "','" + downOver + "'";
setCookie(grp, cmd);
var docGroup = FindGroup(grp, imageName, false);
if (!docGroup || !downSrc) {
return;
}
obj = FWFindImage(document, imageName, 0);
var theImages = docGroup.theImages;
if (theImages) {
for (i = 0; i < theImages.length; i++) {
var curImg = theImages;
if (curImg && curImg != obj) {
curImg.atRestSrc = curImg.initialSrc;
curImg.isDown = false;
obj.downOver = false;
curImg.src = curImg.initialSrc;
}
}
}
obj.atRestSrc = downSrc;
obj.downOver = downOver;
obj.src = downOver;
obj.isDown = true;
}

function GrpSwap(grp) {
var i, j = 0, newSrc, objName;
var docGroup = false;
for (i = 1; i < (GrpSwap.arguments.length - 1); i += 2) {
objName = GrpSwap.arguments;
newSrc = GrpSwap.arguments[i + 1];
docGroup = FindGroup(grp, objName);
if (!docGroup) {
continue;
}
obj = FWFindImage(document, objName, 0);
if (!obj) {
continue;
}
if (obj.isDown) {
if (obj.downOver) {
obj.src = obj.downOver;
}
} else {
obj.src = newSrc;
obj.atRestSrc = obj.initialSrc;
}
obj.skipMe = true;
j++;
}
if (!docGroup) {
return;
}
theImages = docGroup.theImages;
if (theImages) {
for (i = 0; i < theImages.length; i++) {
var curImg = theImages;
if (curImg.atRestSrc && !curImg.skipMe) {
curImg.src = curImg.atRestSrc;
}
curImg.skipMe = false;
}
}
}

function GrpRestore(grp) {
var docGroup = eval("document.FWG_" + grp);
if (!docGroup) {
return;
}
theImages = docGroup.theImages;
if (theImages) {
for (i = 0; i < theImages.length; i++) {
var curImg = theImages;
if (curImg.atRestSrc) {
curImg.src = curImg.atRestSrc;
}
}
}
}
// stop hiding -->

</script>


QUIZ CONFIG FILE (quizconfig.js)
/***********************************************
* JavaScriptKit.com Multiple Choice Quiz Script (* Copyright 2003 JavaScript Kit- * This notice and footnote must stay intact for use
* Visit JavaScript Kit ( for full source code
***********************************************/

//Enter total number of questions:
var totalquestions=10

//Enter the solutions corresponding to each question:
var correctchoices=new Array()
correctchoices[1]='a' //question 1 solution
correctchoices[2]='b' //question 2 solution, and so on.
correctchoices[3]='b'
correctchoices[4]='a'
correctchoices[5]='d'
correctchoices[6]='a'
correctchoices[7]='a'
correctchoices[8]='d'
correctchoices[9]='a'
correctchoices[10]='c'

/////Don't edit beyond here//////////////////////////

function gradeit(){
var incorrect=null
for (q=1;q<=totalquestions;q++){
var thequestion=eval("document.myquiz.question"+q)
for (c=0;c<thequestion.length;c++){
if (thequestion[c].checked==true)
actualchoices[q]=thequestion[c].value
}

if (actualchoices[q]!=correctchoices[q]){ //process an incorrect choice
if (incorrect==null)
incorrect=q
else
incorrect+="/"+q
}
}

if (incorrect==null)
incorrect="a/b"
document.cookie='q='+incorrect
if (document.cookie=='')
alert("Your browser does not accept cookies. Please adjust your browser settings.")
else
window.location="results.htm"
}


function showsolution(){
var win2=window.open("","win2","width=210,height=350, scrollbars")
win2.focus()
win2.document.open()
win2.document.write('<title>Solution</title>')
win2.document.write('<body bgcolor="#FFFFFF">')
win2.document.write('<center><h3>Skill Check Answers</h3></center>')
win2.document.write('<center><font face="Arial">')
for (i=1;i<=totalquestions;i++){
for (temp=0;temp<incorrect.length;temp++){
if (i==incorrect[temp])
wrong=1
}
if (wrong==1){
win2.document.write("Question "+i+"="+correctchoices.fontcolor("red")+"<br>")
wrong=0
}
else
win2.document.write("Question "+i+"="+correctchoices+"<br>")
}
win2.document.write('</center></font>')
win2.document.write("<h5>The answers in red are the ones you incorrectly answered. <p>© Business Training Experts.</p></h5><p align='center'>")
win2.document.close()
}
 
You can email someone by forcing the browser to a mailto: URL... something like this:

Code:
var subject = escape('Your subject here');
var message = escape('Put your message here. Use \n to create a line break');
window.location = 'mailto:recipients@address.com?subject=' + subject + '&body=' + message;

Hope this helps,
Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 

Incidentally, you might want to keep your message as short as possible. Some mail clients will not handle as much data as others.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top