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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Another Confused Newbie

    Hey guys, I am new to javascript and I thought I had a small feel for the language.. I even thought I wrote something that performed a function. www.3rdoct.org/zig/quiz.html is my little quiz template.. now it seems to work fine in IE but in netscape and Firefox some people report it just endlessly loading at the result page or just not loading at all to begin with.. any ideas?

    -Ziggah

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    a = 0
    b = 0
    c = 0
    d = 0
    e = 0
    f = 0
    g = 0
    function zig()
    {
     if (document.getElementById("answer1").checked==true)
     {
     e=e+10
     }
     else if (document.getElementById("answer1").checked==false)
     {
     }
     if (document.getElementById("answer2").checked==true)
     {
     e=e+5
     }
     else if (document.getElementById("answer2").checked==false)
     {
     }
     if (document.getElementById("answer3").checked==true)
     {
     a=a+10
     }
     else if (document.getElementById("answer3").checked==false)
     {
     }
     if (document.getElementById("answer4").checked==true)
     {
     e=e+20
     }
     else if (document.getElementById("answer4").checked==false)
     {
     }
     if (document.getElementById("answer5").checked==true)
     {
     e=e+5
     }
     else if (document.getElementById("answer5").checked==false)
     {
     }
     if (document.getElementById("answer6").checked==true)
     {
     e=e+10
     }
     else if (document.getElementById("answer6").checked==false)
     {
     }
     if (document.getElementById("answer7").checked==true)
     {
     e=e+20
     }
     else if (document.getElementById("answer7").checked==false)
     {
     }
     if (document.getElementById("answer8").checked==true)
     {
     a=a+10
     }
     else if (document.getElementById("answer8").checked==false)
     {
     }
    if (a==0 && e==0)
    {
    document.write("e:"+e + "<br/> " + "a:"+a+"<br/>" + "You did not select anything.."+ "<br>")
    }
    else if (a>0 || e>0)
    {
    document.write("e:"+e + "<br/> " + "a:"+a+"<br/>" + "Explanation: With this code I get to define how each of my variables are effected by selected answers, thus allowing me to later effect the test results, in this case e will equal ineptitude while a will equal aptitude. Or Something.")
    }
    }
    </script>
    </head>
    <body>
    <script type="text/javascript">
    
    </script>
    <form action="">
    This is a sample quiz I guess. How many licks does it take to get to the center of a tootsie pop?
    <br />
    <input type="radio" name="question1" id="answer1"/> 
    ahh one...
    <br />
    <input type="radio" name="question1" id="answer2"/> 
    ahh two...
    <br />
    <input type="radio" name="question1" id="answer3"/>
    ahh three...
    <br />
    <input type="radio" name="question1" id="answer4"/>
    can't tell :(
    </form>
    <form action="">
    <br />
    This is sample question two.. I suppose. What color is the sky?
    <br />
    <input type="radio" name="question2" id="answer5"/> 
    Whats a sky?
    <br />
    <input type="radio" name="question2" id="answer6"/> 
    Huh?
    <br />
    <input type="radio" name="question2" id="answer7"/>
    (drooling)
    <br />
    <input type="radio" name="question2" id="answer8"/>
    Blue at day and black at night
    <br />
    <br />
    <input type="submit" name="submit" id="submit" value="Complete Test" onclick="zig()" /> 
    -Zig
    </form>
    </body>
    </html>
    Last edited by ziggah; 12-05-2006 at 05:06 AM. Reason: adding code

  • #2
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,718
    Thanks
    0
    Thanked 240 Times in 235 Posts
    Hi there ziggah,

    you need to use document.close()...
    Code:
    
    document.write("e:"+e + "<br/> " + "a:"+a+"<br/>" + "You did not select anything.."+ "<br>");
    document.close();
    }
    else if (a>0 || e>0)
    {
    document.write("e:"+e + "<br/> " + "a:"+a+"<br/>" + "Explanation: With this code I get to define how each of my variables are effected by selected answers, thus allowing me to later effect the test results, in this case e will equal ineptitude while a will equal aptitude. Or Something.")
    document.close();
    

    Of course, having said that, you should not be using document.write() in the first place.

    Source:-
    coothead

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    blast! *sheds a tear for document.write()* rest in peace old friend.

  • #4
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,718
    Thanks
    0
    Thanked 240 Times in 235 Posts
    Hi there ziggah,

    once you finally bury it, you will not miss it at all.

    coothead


  •  

    Posting Permissions

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