Click to See Complete Forum and Search --> : Need help!!!!!


jlapdog
08-09-2003, 11:10 AM
Problem: Need a working javascript to send users to a url based on their score.

Background: I am designing a course using Dreamweaver for the Rules of the Road (Maritime). I am utilizing the CourseBuilder Exntension, which has been helpful thus far, but now I need human interaction and need help. I have a twenty question test, each question on a different page, setup in frames, where the bottom frame keeps track of the users score. After the user submits their answer to the 20th question, the user is sent to a results page and I am trying to put a javascript in there that will send the student to a different page if his score is less than an 80. Here is the code that I did myself, which is not working.

<script language="JavaScript">
if ((top.cmiresults.total)>=80) then {window.content='testa-results.htm'} else {window.content='testa-retest.htm'};
</script>

My frames are named content (99%) and results (1%)

Also, is it possible to add a script to the 20th question button that will do the same function on that page? I have two other scripts which add the number correct and to the total score already for that button.

Any help?

AdamGundry
08-09-2003, 11:13 AM
I think you want this:

<script type="text/javascript">
if (top.cmiresults.total>=80){
content.location = 'testa-results.htm'
} else {
content.location = 'testa-retest.htm'
}
</script>

Adam

P.S. Be aware that your pages should be accessible with Javascript disabled, assuming this is for use by the general public.

jlapdog
08-09-2003, 11:20 AM
didn't work :(

AdamGundry
08-09-2003, 11:22 AM
In that case, you'll need to post the rest of your code (a link or the full source here) so I can see the error.

Adam

jlapdog
08-09-2003, 11:23 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Question 6 - Test A</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="BluwaterArialNew.css" rel="stylesheet" type="text/css">
<script language="JavaScript"></script>
<script language="JavaScript" src="scripts/behActions.js"></script>
<script language="JavaScript" src="scripts/behCourseBuilder.js"></script>
<script language="JavaScript" src="scripts/interactionClass.js"></script>
<script language="JavaScript" src="scripts/elemIbtnClass.js"></script>
<script language="JavaScript" src="scripts/elemTimrClass.js"></script>
<script language="JavaScript" type="text/javascript">
if (top.cmiresults.total>=80){
content.location = 'testa-results.htm'
} else {
content.location = 'testa-retest.htm'
}
</script>
</head>

<body onLoad="MM_initInteractions()">
<div id="Layer1" style="position:absolute; z-index:1; left: 182px; top: 9px; width: 400px; height: 108px;" onMouseOver="MM_setTextOfLayer('Layer1','','%3Ccenter%3EYou scored '+(top.cmiresults.numCorrect)+' correct out of a total of '+(top.cmiresults.numQuestions)+' questions. %3Cp%3E%0D%0AYour Test A score is '+(top.cmiresults.total)+'%25.%0D%0A%3C/center%3E ')"></div>
<div id="Layer2" style="position:absolute; left:180px; top:123px; width:403px; height:142px; z-index:2"></div>

</body>
</html>

AdamGundry
08-09-2003, 11:29 AM
I'm guessing at the effects of the other code there (that's an awful lot of JS), but I think you might be able use this:

<script type="text/javascript">
function checkTotal(){
if (top.cmiresults.total>=80){
location = 'testa-results.htm'
} else {
location = 'testa-retest.htm'
}
}
</script>
...
<body onLoad="MM_initInteractions();checkTotal()">

Adam

P.S. The language attribute of <script> is now deprecated - you should use type instead.

jlapdog
08-09-2003, 11:34 AM
OHH YAHHHHHHHHHHHH!!!!!

That worked... thanks a ton.... appreciate the help...