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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Online Quiz Javascript Question

Status
Not open for further replies.

OSnapple

Programmer
Dec 19, 2006
3
US
I have created an online quiz using Quiz Maker 2.0. It uses a JavaScript Function in the <head> section to display a page of results when you click the submit button at the end of the quiz.
My question is, is there a way that the outputted HTML code (that the JavaScript Function creates) could be sent to my e-mail. If e-mail is not an option, what are other ways I can save this data?

It is a rather lengthy function, but if I need to I can post the important parts of it

Thanks in advance


~Snapple
 
JavaScript is a Client side programming Language.
This means it does not interact with the server at all.
Therefore not having access to an email server to send the results.

There is a way you can send for data to your email using the clients email i think. But they are prompt that this is about to happen.

You would need another programming language to work along side your javascript to make this happen. (i.e. php)

Ill see if I can find a link on how to do this.

Ill get back to you.

Drew
 
Here is some code on how to send email using a form and no other server side language.
Code:
<form action="mailto:you@yourdmainhere.com" method="post" enctype="text/plain" >
FirstName:<input type="text" name="FirstName">
Email:<input type="text" name="Email">
<input type="submit" name="submit" value="Submit">
</form>

source:

Maybe this will work for you.

Drew
 
Thanks

I understand most of that but here is my catch, the javascript actually grades the test instantly. I would like the graded info sent to me,

Code:
<script language='JavaScript'>
<!--
function gradeit(){var qnum=50;
var qname='Pre-Employment Quiz';
var ghtml='';
var right=0;
var wrong=0;
var grade=0;
var gmethod=1;
var qarray=new Array()
qarray[0]='Select the correct place for the name in the box:';
qarray[1]='Select the correct place for the name in the box:';
qarray[2]='Select the correct place for the name in the box:';
qarray[3]='Select the correct place for the name in the box:';
qarray[4]='Select the correct place for the name in the box:';
qarray[5]='16 + 378 + 3 =';
qarray[6]='600,030 - 29,026 =';
qarray[7]='1704 x 605 =';
qarray[8]='11,158 ÷ 58 =';
qarray[9]='21.4 + 8.05 + 63 =';
qarray[10]='George Adams';
qarray[11]='Donnelly & Fitch, Inc.';
qarray[12]='Hobart Hunter III';
qarray[13]='Gnu Industries';
qarray[14]='Franco Fernandez';
qarray[15]='Island Group, Ltd.';
qarray[16]='Geoffrey Daniels';
qarray[17]='Ghosts, Goblins & Gremlins, Assoc.';
qarray[18]='Highway Apartments';
qarray[19]='Horatio Franklin Alger';
qarray[20]='Select the word (if any) that is spelled correctly:';
qarray[21]='Select the word (if any) that is spelled correctly:';
qarray[22]='Select the word (if any) that is spelled correctly:';
qarray[23]='Select the word (if any) that is spelled correctly:';
qarray[24]='Select the word (if any) that is spelled correctly:';
qarray[25]='Shawn Scheirer Auto Sales - Shawn Schierer Auto Sales';
qarray[26]='Linsley-Morrissey Sales, Inc.  -  Lindsey-Morrissey Sales, Inc.';
qarray[27]='Club Nautica of Pittsburgh - Club Nautica of Pittsburgh';
qarray[28]='Bob Thomas Honda-Kawasaki of Irwin - Bob Thomas Honda-Kawasaki of Irvin';
qarray[29]='11200 Perry Highway / Route 19 - 11200 Perry Highway / Route 19';
qarray[30]='Select the word (if any) that is spelled correctly:';
qarray[31]='Select the word (if any) that is spelled correctly:';
qarray[32]='Select the word (if any) that is spelled correctly:';
qarray[33]='Select the word (if any) that is spelled correctly:';
qarray[34]='Select the word (if any) that is spelled correctly:';
qarray[35]='345 Mt. Lebanon Blvd.; PGH 345 Mt. Lebonan Blvd.; PGH';
qarray[36]='AEA Technology & Engineering, Corp. AEA Technology & Engineering, Corp.';
qarray[37]='1254 East Northwest Blvd. 1254 East NorthWest Blvd.';
qarray[38]='Martin Thomassohn, Jr, Ph.D Martin Thomassohn, Jr., Ph.D';
qarray[39]='Sarah Michelle Pieffer, MSN Sarah Michelle Pieffer, MSN';
qarray[40]='Select the correct place for the name in the box:';
qarray[41]='Select the correct place for the name in the box:';
qarray[42]='Select the correct place for the name in the box:';
qarray[43]='Select the correct place for the name in the box:';
qarray[44]='Select the correct place for the name in the box:';
qarray[45]='300 - 64.7 =';
qarray[46]='0.15 x 0.06';
qarray[47]='1.8 ÷ 72 =';
qarray[48]='What is 4/5 of 90?';
qarray[49]='What is 40% of 120?';
var canswerarray=new Array()
canswerarray[0]='2';
canswerarray[1]='1';
canswerarray[2]='2';
canswerarray[3]='3';
canswerarray[4]='1';
canswerarray[5]='0';
canswerarray[6]='1';
canswerarray[7]='1';
canswerarray[8]='2';
canswerarray[9]='3';
canswerarray[10]='0';
canswerarray[11]='1';
canswerarray[12]='3';
canswerarray[13]='2';
canswerarray[14]='0';
canswerarray[15]='3';
canswerarray[16]='1';
canswerarray[17]='2';
canswerarray[18]='2';
canswerarray[19]='0';
canswerarray[20]='1';
canswerarray[21]='2';
canswerarray[22]='3';
canswerarray[23]='1';
canswerarray[24]='2';
canswerarray[25]='1';
canswerarray[26]='1';
canswerarray[27]='0';
canswerarray[28]='1';
canswerarray[29]='0';
canswerarray[30]='1';
canswerarray[31]='0';
canswerarray[32]='3';
canswerarray[33]='1';
canswerarray[34]='2';
canswerarray[35]='1';
canswerarray[36]='0';
canswerarray[37]='1';
canswerarray[38]='1';
canswerarray[39]='0';
canswerarray[40]='0';
canswerarray[41]='2';
canswerarray[42]='0';
canswerarray[43]='1';
canswerarray[44]='3';
canswerarray[45]='3';
canswerarray[46]='1';
canswerarray[47]='0';
canswerarray[48]='2';
canswerarray[49]='2';
var answerarray=new Array()
answerarray[0]=new Array('A','B','C','D')
answerarray[1]=new Array('A','B','C','D')
answerarray[2]=new Array('A','B','C','D')
answerarray[3]=new Array('A','B','C','D')
answerarray[4]=new Array('A','B','C','D')
answerarray[5]=new Array('397','427','434','437')
answerarray[6]=new Array('750,004','570,903','571,004','629,016')
answerarray[7]=new Array('114,760','1,030,920','1,034,920','1,036,970')
answerarray[8]=new Array('109 R 36','119 R 36','192 R 22','None of these')
answerarray[9]=new Array('1.282','16.49','30.08','92.45')
answerarray[10]=new Array('Aa -- Cd','Ce -- Fh','Fi -- Gl','Gm -- Ht')
answerarray[11]=new Array('Aa -- Cd ','Ce -- Fh','Fi -- Gl','Gm -- Ht')
answerarray[12]=new Array('Ce -- Fh','Fi -- Gl','Gm -- Ht','Hu -- Jm')
answerarray[13]=new Array('Ce -- Fh','Fi -- Gl','Gm -- Ht','Hu -- Jm')
answerarray[14]=new Array('Ce -- Fh','Fi -- Gl','Gm -- Ht','Hu -- Jm')
answerarray[15]=new Array('Ce -- Fh','Fi -- Gl','Gm -- Ht','Hu -- Jm ')
answerarray[16]=new Array('Aa -- Cd','Ce -- Fh','Fi -- Gl','Gm -- Ht')
answerarray[17]=new Array('Aa -- Cd','Ce -- Fh','Fi -- Gl','Gm -- Ht')
answerarray[18]=new Array('Aa -- Cd','Fi -- Gl','Gm -- Ht','Hu -- Jm ')
answerarray[19]=new Array('Aa -- Cd','Ce -- Fh','Fi -- Gl','Gm -- Ht')
answerarray[20]=new Array('calendar','calender','calander','none of these')
answerarray[21]=new Array('merchendice','merchandice','merchandise','none of these')
answerarray[22]=new Array('competant','compitent','compettent','none of these')
answerarray[23]=new Array('apperant','apparent','appearant','none of these')
answerarray[24]=new Array('insistant','incistant','insistent','none of these')
answerarray[25]=new Array('same','different','same','different')
answerarray[26]=new Array('same','different','same','different')
answerarray[27]=new Array('same','different','same','different')
answerarray[28]=new Array('same','different','same','different')
answerarray[29]=new Array('same','different','same','different')
answerarray[30]=new Array('confidance','confidence','confedense','none of these')
answerarray[31]=new Array('disappoint','dissapoint','diseppoint','none of these')
answerarray[32]=new Array('defendent','deffendent','diffendant','none of these')
answerarray[33]=new Array('amung','among','ammung','none of these')
answerarray[34]=new Array('occassionnally','occassionally','occasionally','none of these')
answerarray[35]=new Array('same','different','same','different')
answerarray[36]=new Array('same','different','same','different')
answerarray[37]=new Array('same','different','same','different')
answerarray[38]=new Array('same','different','same','different')
answerarray[39]=new Array('same','different','same','different')
answerarray[40]=new Array('A','B','C','D')
answerarray[41]=new Array('A','B','C','D')
answerarray[42]=new Array('A','B','C','D')
answerarray[43]=new Array('A','B','C','D')
answerarray[44]=new Array('A','B','C','D')
answerarray[45]=new Array('347','335.3','236.7','235.3')
answerarray[46]=new Array('0.009','0.09','0.90','90')
answerarray[47]=new Array('0.025','0.25','2.5','4')
answerarray[48]=new Array('20','40.5','72','80')
answerarray[49]=new Array('30','33.3','48','80')
ghtml+='<p align=\"center\"><span class=\"header\">'+qname+'</span></p>';
for(i=0;i<qnum;i++){
	for(a=0;a<4;a++){
		var rbid='rb'+i+'_'+a;
		if(document.getElementById(rbid).value=='1'&&document.getElementById(rbid).checked==true){
			ghtml+='<table width=\"100%\"><tr><td style=\"border:1 solid black;background-color:lightyellow\"><span style=\"color:green\"><b>Correct</b></span></td></tr><tr><td style=\"border:1 solid black;background-color:lightyellow\"><b>'+eval(i+1)+'. '+qarray[i]+'</b><p><table width=\"100%\"><tr><td width=\"50%\"><i><span style=\"color:green\">Your Answer</span>:</i> '+answerarray[i][a]+'</td><td width=\"50%\"><i><span style=\"color:green\">Correct Answer</span>:</i> '+answerarray[i][canswerarray[i]]+'</td></tr></table></td></tr></table><p>&nbsp;';
			right++;		}
		if(document.getElementById(rbid).value=='0'&&document.getElementById(rbid).checked==true){
			ghtml+='<table width=\"100%\"><tr><td style=\"border:1 solid black;background-color:lightyellow\"><span style=\"color:red\"><b>InCorrect</b></span></td></tr><tr><td style=\"border:1 solid black;background-color:lightyellow\"><b>'+eval(i+1)+'. '+qarray[i]+'</b><p><table width=\"100%\"><tr><td width=\"50%\"><i><span style=\"color:red\">Your Answer</span>:</i> '+answerarray[i][a]+'</td><td width=\"50%\"><i><span style=\"color:green\">Correct Answer</span>:</i> '+answerarray[i][canswerarray[i]]+'</td></tr></table></td></tr></table><p>&nbsp;';
			wrong++;		}
	}
}
if(gmethod==0){ghtml+='<div align=\"center\"><table width=\"100%\" bgcolor=\"lightyellow\"><tr><td width=\"100%\"><span style=\"font-size:14pt\"><b>Grade</b></span></td></tr><tr><td width=\"100%\"><table width=\"100%\"><tr><td width=\"50%\"><b><u>Correctly Answered Questions</u>:</b> '+right+'</td><td width=\"50%\"><b><u>InCorrectly Answered Questions</u>:</b> '+wrong+'</td></tr></table></td></tr></table>';}
if(gmethod==1){
	grade=100/qnum;
	right=grade*right;
	wrong=grade*wrong;
	ghtml+='<div align=\"center\"><table width=\"100%\" bgcolor=\"lightyellow\"><tr><td width=\"100%\"><span style=\"font-size:14pt\"><b>Grade</b></span></td></tr><tr><td width=\"100%\"><table width=\"100%\"><tr><td width=\"50%\"><b><u>Correctly Answered Questions</u>:</b> '+right+'%</td><td width=\"50%\"><b><u>InCorrectly Answered Questions</u>:</b> '+wrong+'%</td></tr></table></td></tr></table>';}
ghtml+='<p align=\"center\"><input type=\"button\" value=\"Reset\" onClick=\"location.reload()\"/>';
document.getElementById('qview').style.display='none';
document.getElementById('gradeview').style.display='inline';
document.getElementById('gradeview').innerHTML=ghtml;
}
 //-->
</script>
 
The small code i showed you above will show the information the user sent in their email client.

If you want to do it like other sites, you will have to look into another language to submit the email from the servers end.

Basically the program will have to take the JS results, and sent it to your web sever, then send using the email server on the web server.

Its very easy if you can program in a server side language.

here are some languages you should look into.

PHP and ASP.NET

As you can see i said the word "server" a dozen times over.
JavaScript is Client Side. This means the client (u and me) interpret the code with our browsers. This is why its so fast)

A server side language does all the processing, calculations etc on the server. Therefore requesting a new web page output.

I hope i did not confuse to too much.

Php is fun. I like the language a lot.

You will have to ensure your web hosting site can also allow you to use a server side languages. A LOT of free hosting sites do NOT allow such programming to take place.

Hope this explains things a bit

Drew
 
I am excellent at troubble shooting PHP and know the basics but for this project i might be in over my head.

What i cant figure out is how to capture the result of the function gradeit(), Once i capture that output i will be fine.

So how can i collect that output then set up a sendmail.php for it to get to me.

~Snapple
 
Can i See your page, so i can view the whole source ?

You dont have to post it in here. thats too much code :)

if you point me to the URL ill view Source and take a peak.

It should be easy i think..


Drew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top