...

View Full Version : Quiz Script Thing..Help Please



bbg5000
06-29-2004, 04:36 PM
Got this script(seen below). Anyways, its one of those quiz scripts. Like.. you have a quiz, blah blah. Anyways, I've got 5 images used as the results. Anyways, I don't want the images to be in the same folder as the actual code. I want them in a sub-folder, but it don't like me and doesn't want to work that way. Any suggestions??!



<script lang="JavaScript">
<!--
function results(formName)
{
var alpha = 0;
var bravo = 0;
var charlie = 0;
var delta = 0;
var echo = 0;
var value = "";


for( var i = 0; i < document.forms[formName].elements.length -1; i += 5)
{
for( var j = i; j < i+5; j++)
// j is the answers
{
if( document.forms[formName].elements[j].checked )
value = document.forms[formName].elements[j].value;
}
switch( value )
{
case 'a': alpha++; break;
case 'b': bravo++; break;
case 'c': charlie++; break;
case 'd': delta++; break;
case 'e': echo++; break;
}
}

var url = "alpha";
var topcount = alpha;
if( bravo > topcount ) { url = "bravo"; topcount = bravo; }
if( charlie > topcount ) { url = "charlie"; topcount = charlie; }
if( delta > topcount ) { url = "delta"; topcount = delta; }
if( echo > topcount ) { url = "echo"; topcount = echo; }
window.open(url + ".gif", "results");
if(alpha == topcount && url != "alpha")
window.open("alpha.gif", "results2");
if(bravo == topcount && url != "bravo")
window.open("bravo.gif", "results3");
if(charlie == topcount && url != "charlie")
window.open("charlie.gif", "results4");
if(delta == topcount && url != "delta")
window.open("delta.gif", "results5");
if(echo == topcount && url != "echo")
window.open("echo.gif", "results6");




}
//-->
</script>

And the HTML looks something like..



<form name="quiz">
<p align="left">
<b><font color="#000000" size="3">1. Question 1 </font></b>

<font size="2" color="#000000">
<input type="radio" name="1" value="e">Option 1 <br>
<input type="radio" name="1" value="d">Option 2 <br>
<input type="radio" name="1" value="a">Option 3 <br>
<input type="radio" name="1" value="b">Option 4 <br>
<input type="radio" name="1" value="c">Option 5 <br><br>
</font>

<input type="button" value="Submit" onclick="results('quiz');">
</p>
</form>


Only there's 9 other(10 in total) questions. The code works fine. I just want the images (alpha.gif, bravo.gif, charlie.gif, etc..) to be in a subfolder.

Thanks.

Mr J
06-29-2004, 07:23 PM
It all depends on where you are putting your images.

Example:

If the folder (pics) containing the images is in the same folder as the code

pics/alpha.gif

If the images are in a folder outside the folder containing the code

../pics/alpha.gif

glenngv
06-30-2004, 07:34 AM
var dir = "images/"; //if 'images' folder is a subfolder in the current directory
//var dir = "../images/"; //if 'images' folder is in the same level of the current directory

var url = "alpha";
var topcount = alpha;
if( bravo > topcount ) { url = "bravo"; topcount = bravo; }
if( charlie > topcount ) { url = "charlie"; topcount = charlie; }
if( delta > topcount ) { url = "delta"; topcount = delta; }
if( echo > topcount ) { url = "echo"; topcount = echo; }
window.open(dir + url + ".gif", "results");
if(alpha == topcount && url != "alpha")
window.open(dir +"alpha.gif", "results2");
if(bravo == topcount && url != "bravo")
window.open(dir +"bravo.gif", "results3");
if(charlie == topcount && url != "charlie")
window.open(dir +"charlie.gif", "results4");
if(delta == topcount && url != "delta")
window.open(dir +"delta.gif", "results5");
if(echo == topcount && url != "echo")
window.open(dir +"echo.gif", "results6");



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum