|
|
|
|
![]() ![]() |
Dec 3 2007, 01:47 PM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 259 Joined: 18-July 07 From: Slough (UK) Member No.: 46,682 |
I found a nice program which allows you to put quizzes on your web site.
You can design your own questions, set the layout of your page, and there is also a possibility of having the results emailed to you. It further offers a facility to store the results and all that, all you have to do is put a link in the program, telling it which page takes care of that. However, when I look at the HTML code the program generates, I see that most of it is written in Javascript. Obviously, it also uses variable names, but as I don't know any Java, I was wondering if those variables are exchangeable with PHP, in order to let it store the name of the quizzer and his/her results in a MySQL database, or whether Javascript can address the issue directly. If this question is not clear enough or if people require more information in order to answer the question, I can always post the HTML code of the page here. |
|
|
|
Dec 3 2007, 02:09 PM
Post
#2
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 3,882 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
Java and javascript are two different programming languages.
javascript is a client-side scripting language and Java is a full programming language capable of much more. Please confirm which one you are discussing. javascript is used in AJAX to connect to databases and provide interactive web pages. I am just about to learn some Ajax, so I can't provide any more info than this. |
|
|
|
Dec 3 2007, 06:27 PM
Post
#3
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 259 Joined: 18-July 07 From: Slough (UK) Member No.: 46,682 |
Well, yes, sorry about the confusion.
It is Javascript of course. The tags say QUOTE <script language="JavaScript"> .Just to see if it would help, or ring any bells, here is the code for the entire page (a whole, but short quiz with 5 questions): QUOTE <HTML> <HEAD> <TITLE>Vlaanderen</TITLE> <META NAME="Generator" CONTENT="SolidSoftware's KwizMaker v1.0 ©2002"> <META NAME="Author" CONTENT=""> <script language="JavaScript" src="clock.js"> </script> <script language="JavaScript"> <!-- document.oncontextmenu=new Function("return false"); function login(){ document.location = "http://www.vlaanderen-flanders.org.uk"; } var ans = new Array; var yourtry = new Array; var thisscore = 0; var x; var secsAllowed=15; var count=5; var choice=3; var username; var email; ans[1]="A"; ans[2]="C"; ans[3]="B"; ans[4]="C"; ans[5]="C"; for (x=1;x<=count;x++) yourtry[x]=""; function storetry(question, answer){ yourtry[question] = answer; } function getscore(){ var y; thisscore = 0; setCookie('save', 'false', 365); for (y=1;y<=count;y++) { if (yourtry[y] =="") { alert("Please answer ALL questions"); return(false); } else if (yourtry[y] == ans[y]) thisscore++; } alert("Your Score is: " + Math.round(thisscore/count*100)+"%"); document.quizform.score.value = Math.round(thisscore/count*100)+"%"; document.quizform.name.value = username; document.quizform.email.value = email; document.quizform.lapsed.value = lapsedtimestr; if (thisscore<count)showerrors(); return(true); } function showerrors(){ var h; var v =145+((count-thisscore)*20); h = "top=0,left=0,width=180,"; h = h + "height=" + v; h = h + ",scrollbars=1"; var i; var newwin; newwin = window.open("", "", h); newwin.document.write("<FONT size=4><B>Your Error(s)...</B><BR><BR>"); for(i = 1; i<= count;i++){ if (yourtry[i] != ans[i]){ newwin.document.write("\nQuestion: " + i); newwin.document.write("<BR>"); } } newwin.document.write("<BR><B>Have another try...</B><BR><BR></FONT>"); newwin.document.write('<BUTTON onclick="window.close()">Close</BUTTON>'); } function refresh(){ document.location.reload(); document.quizform.reset(); } function getCookie(NameOfCookie) { if (document.cookie.length > 0) { begin = document.cookie.indexOf(NameOfCookie+"="); if (begin != -1) { begin += NameOfCookie.length+1; end = document.cookie.indexOf(";", begin); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(begin, end)); } } return null; } function savequiz(){ setCookie('quizuser',document.quizform.name.value,365); setCookie('QuizID',document.quizform.ID.value,365); setCookie('save', 'true', 365); for (x=1; x<=count;x++) setCookie('q'+x, yourtry[x], 365); } function setCookie(NameOfCookie, value, expiredays){ var ExpireDate = new Date (); ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000)); document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()); } function docookies(){ var con; username=getCookie('username'); email=getCookie('email'); if (username==null) { alert('Please log in'); window.location = "http://www.vlaanderen-flanders.org.uk"; } else { document.quizform.name.value = username; if ((getCookie('QuizID') == document.quizform.ID.value) && (getCookie('save')== 'true') && (getCookie('quizuser') == document.quizform.name.value)) { con = confirm('Saved quiz found. OK to continue, Cancel to restart.'); if (con) getsave(); } } } function getsave() { var c; var found = false; var y = 0; var ch = 0; for(x=1; x<=count;x++) { found = false; c = getCookie('q'+x); yourtry[x] = c; while(found ==false){ if ((document.quizform.elements[y].value == c) && (document.quizform.elements[y].type == "radio")) { document.quizform.elements[y].checked = true; found = true; } y=y+1; ch=ch+1; } y = y + choice-ch; ch=0; } } //--> </SCRIPT> </HEAD> <BODY onload="docookies();startclock(); checkLocation()" onUnload="refresh()" BGCOLOR="#FFFFFF" TEXT="#FFFFFF" BGPROPERTIES="fixed" > <DIV ID="object1" STYLE="position:relative; visibility:show; left:85%; top:0px; z-index:2"> <TABLE BORDER="4" BGCOLOR="#000000" CELLPADDING="0" CELLSPACING="0"> <TR><TD VALIGN="top" ALIGN="left" ><img src="0fdg.gif" name=min ><img src="0fdg.gif" name=minu><img src="cfdg.gif" name=gap ><img src="0fdg.gif" name=sec ><img src="0fdg.gif" name=secu ></TD></TR> </TABLE> </DIV> <H1 ALIGN=CENTER> <FONT FACE="sans-serif" SIZE="6" COLOR="#000000"> Vlaanderen </FONT> </H1> <HR> <FORM NAME=quizform method="POST" action="http://www.vlaanderen-flanders.org.uk/quiz/results.php" onSubmit="return getscore()"> <P align="LEFT"> <FONT FACE="serif" SIZE="3" COLOR="#FFFFFF"> <B> Question 1: Wie was eerste minister in 1978?</B><BR><BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> a: <input type=radio value=A name=q1 onclick="storetry(1, this.value)">Wilfried Martens<BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> b: <input type=radio value=B name=q1 onclick="storetry(1, this.value)">Hugo Schiltz<BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> c: <input type=radio value=C name=q1 onclick="storetry(1, this.value)">Leo Tindemans<BR> </FONT> <BR><BR><HR width="50%"><BR> </p> <P align="LEFT"> <FONT FACE="serif" SIZE="3" COLOR="#FFFFFF"> <B> Question 2: Wat is de echte naam van 'Madame Non'?</B><BR><BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> a: <input type=radio value=A name=q2 onclick="storetry(2, this.value)">Noella Millequet<BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> b: <input type=radio value=B name=q2 onclick="storetry(2, this.value)">Joelle Milliquet<BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> c: <input type=radio value=C name=q2 onclick="storetry(2, this.value)">Joelle Milquet<BR> </FONT> <BR><BR><HR width="50%"><BR> </p> <P align="LEFT"> <FONT FACE="serif" SIZE="3" COLOR="#FFFFFF"> <B> Question 3: Wie is de onlangs mislukte formateur?</B><BR><BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> a: <input type=radio value=A name=q3 onclick="storetry(3, this.value)">Didier Reynders<BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> b: <input type=radio value=B name=q3 onclick="storetry(3, this.value)">Yves Leterme<BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> c: <input type=radio value=C name=q3 onclick="storetry(3, this.value)">Olivier Maingain<BR> </FONT> <BR><BR><HR width="50%"><BR> </p> <P align="LEFT"> <FONT FACE="serif" SIZE="3" COLOR="#FFFFFF"> <B> Question 4: Wanneer was de Guldensporenslag?</B><BR><BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> a: <input type=radio value=A name=q4 onclick="storetry(4, this.value)">11/8/1300<BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> b: <input type=radio value=B name=q4 onclick="storetry(4, this.value)">11/7/1305<BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> c: <input type=radio value=C name=q4 onclick="storetry(4, this.value)">11/7/1302<BR> </FONT> <BR><BR><HR width="50%"><BR> </p> <P align="LEFT"> <FONT FACE="serif" SIZE="3" COLOR="#FFFFFF"> <B> Question 5: Wanneer werd de Gentse universiteit vervlaamst?</B><BR><BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> a: <input type=radio value=A name=q5 onclick="storetry(5, this.value)">1900<BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> b: <input type=radio value=B name=q5 onclick="storetry(5, this.value)">1940<BR> </FONT> <FONT FACE="monospace" SIZE="3" COLOR="#FFFFFF"> c: <input type=radio value=C name=q5 onclick="storetry(5, this.value)">1930<BR> </FONT> <BR><BR> </p> <HR> <BR> <FONT size=+1>If you are not <A NAME="stayput"></A> <input type=text size=30 value="" name="name"> please click <A HREF="#stayput" onClick="login()">here</A>.<BR><BR></Font> <FONT size=+1>Your Score: <font> <input type=hidden name="email" value=""> <input type=hidden name="URL" value="http://www.vlaanderen-flanders.org.uk/dank.htm"> <input type=hidden name=ID value=Nr.1> <input type=hidden name="lapsed" value=""> <input type=text size=5 value="N/A" name=score><BR><BR> <input type=submit value="Check Score" > <input type=reset value=Clear All onClick="refresh()"> <input type=button value=" Close This Window " onclick="self.close()"> </FORM> <HR> </BODY> </HTML> Hope that helps. This post has been edited by mrdee: Dec 3 2007, 06:28 PM |
|
|
|
Dec 3 2007, 06:38 PM
Post
#4
|
|
|
|||[ n00b King ]||| ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 643 Joined: 20-June 07 From: Auckland Member No.: 45,102 |
sorry i did not read your javascript code. I usually don't read long lines of code until I'm fully awake, bored or really have to. But from what you said you want to store variables from javascript to mysql database? well only way to do that is pass javascript variables to PHP. Thats the quick answer.
method 1. post javascript variables using 'get' or 'post' and grabs those in PHP then do mysql queries. method 2. post javascript variables using ajax (post or get) and do the same thing in PHP and Mysql. method 1 is more simpler if you are not familiar with ajax just yet. |
|
|
|
Dec 3 2007, 08:23 PM
Post
#5
|
|
|
Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 975 Joined: 25-September 05 From: The dungeon deep below the foundation of trap17 Member No.: 12,251 |
He's not asking how to do it, from his question, I think he is just wondering if that code IS posting to sql. I do not see any ajax in that code. All of the values are being stored in cookies not sql. If you want to modify that sonesay has some great options for you.
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 26th July 2008 - 01:55 PM |