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

I NEED HELP.....

Status
Not open for further replies.

melstef

Programmer
Feb 19, 2003
69
0
0
CA
this is what I need to do:



As you will notice the quiz/quiz_basic.htm is the same quiz for every site. This is where I think the code should be. I have about 50 site like this and I would like to have the quiz itself in only one place instead of 50 places. By the way I'm not use to work with javascript.

This is my actual code:
<HEAD>

<script language="JavaScript">
<!--

function SymError()
{
return true;
}

window.onerror = SymError;

//-->
</script>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var ans = new Array;
var done = new Array;
done[1] = false;
done[2] = false;
done[3] = false;
done[4] = false;
done[5] = false;
done[6] = false;
done[7] = false;
done[8] = false;
done[9] = false;
done[10] = false;


var score = 0;
ans[1] = "c";
ans[2] = "a";
ans[3] = "c";
ans[4] = "c";
ans[5] = "c";
ans[6] = "a";
ans[7] = "b";
ans[8] = "d";
ans[9] = "b";
ans[10] = "b";



function Engine(question, answer)
{
if (answer != ans[question])
{
if (done[question] == false)
{
alert("Nope. Your score stays at " + score+" points.");
}
else
{
alert("You have already answered this one.");
document.getElementById("quest"+question+"-"+ans[question]).checked = true;
}
//if(done[question] && )
/*else
{
alert("You have already answered this one.");
}*/
}

else
{
if (done[question] == false)
{
done[question] = true;
score++;
alert("Yes! Your score is now " + score+" points.");
}

else
{
alert("You have already answered this one.");
}
}
}

function NextLevel () {
if (score > 10) {
alert("You cheated.");
}
if (score >= 10 && score <= 10) {
self.location="
}
else {
alert("You cannot receive your certificate unless you score "+10+" points.")
}
}
// End -->
</SCRIPT>
<title>Quiz - Junior</title>
<style type="text/css">
<!--
@import url("../fhhweb_body.css");
-->
</style>
<link href="../default.css" rel="stylesheet" type="text/css">
<link href="../fhhweb_body.css" rel="stylesheet" type="text/css">
</head>


Thanks
 
1) Change your NextLevel function to this:

function NextLevel (location) {
if (score > 10) {
alert("You cheated.");
}
if (score == 10) {
self.location= location;
} else {
alert("You cannot receive your certificate unless you score "+10+" points.")
}
}

2) Take all your javascript code from the <!-- to the //--> and paste it into another blank page and label it whatever... quizValidation.js (now it is an independant javascript file)

3) Upload that quizValidation.js file to a location which can be reached by all the pages which use the quiz.

4) Remove all your javascript code from all the pages that use it.

5) Add this, inbetween the <head></head> tags, of all the pages which use the quiz:
<script language="JavaScript" src=" - now all your quiz pages will be referencing this javascript file

6) Under step 5 add this:
<script language="JavaScript">location=' - location is where the url for the quizinfo.htm for that particular quiz, which I am assuming is different for every quiz. So, on every quiz page this would be different.

DONE: Now your quiz is validation for all 50 can be manipulated once and be applied to all quizes, all you have to do is specify where the quizinfo.htm page for each quiz.

Hope this helped.
- Shu
 
Oh yeah, if your quizinfo.htm page is always going to be the same (and in the same location) for every quiz the you can leave your orginal NextLevel function the way it is and skip step 6.

- Shu
 
hello, yes it helped me understand more of javascript. My problem is still there. I want only one quiz_basic.htm for all 50 sites, that would be at hazardhouse.com/quiz_basic.htm. The questions will change and I do not want to change every quiz one by one because they are the same. The difference between them is when the quiz is done, they click go to quizinfo.htm page and after receive a certificate (their own). Is it possible to change this string (<script language="JavaScript">location=' ) with more than one location? Like if they came from address hazardhouse.com/test , then the location would be hazardhouse.com/test/quizinfo.htm and if they came from hazardhouse.com/test2, then the location would be hazardhouse.com/test2/quizinfo.htm

Is this possible???
Thanks
 
How about putting the central quiz page in an iframe, then setting the action based on the top.location.href? Outside of using server-side includes, that would probably be the most flexible way to use one quiz page while keeping the relationship to the original site intact.

Lee
 
it doesn't work because it is a quiz and when they click, they have a popup saying that the answer is correct or not. so with the iframe, I cannot have popup
thanks
 
Sure you can have popups from the page in an iframe. The popup will come from the quiz page where it's always come from. The universal quiz page will be the URL for the iframe, and whatever site the person is on will be the top.location.href.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top