Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Quiz Script Thing..Help Please

    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??!

    Code:
          <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..

    Code:
             <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.

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    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

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    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");


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •