473,565 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

External .js file execution

mb
Hi,

I picked up this JavaScript code (quiz code) at:
http://javascript.internet.com/misce...oice-quiz.html

and modified it (and may have deleted some line I shouldn't have) so
that it looks like this on my web site:

http://www.goalseek.net/Scripts/qa_XL_History.htm

Can someone explain to me why the external files produce on the .htm
page only partially what they are supposed to produce? The code works
just fine if I have 3 questions in the external file, but as soon as I
add a fourth one or more, the .htm page always shows only 4 questions
with the fourth one truncated with only 2 multiple-choice answers.
The arrays and the loops appear OK to me in the external .js files. So,
what's wrong? Your expertise will mightily be appreciated.

In the .htm file, these tags point to the external .js files in the
same directory as the .htm file:

<script text/javascript src="quiz_funct ions.js"></script>
<script text/javascript src="qa_XL_Hist ory.js"></script>

The qa_XL_History.j s code is this ..... :
=============== =============== =============== =
/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by James Crooke ::
http://javascript.internet.com/misce...oice-quiz.html
Modified by: Marc Bertrand :: http://www.goalseek.net*/

var questions = new Array();
var choices = new Array();
var answers = new Array();
// To add more questions, just follow the format below.

questions[0]="1) Statement number 1";
choices[0]=new Array();
choices[0][0]="Correct answer";
choices[0][1]="Incorrect answer";
choices[0][2]="Incorrect answer";
choices[0][3]="Incorrect answer";
answers[0]=choices[0][0];

questions[1]="2) Statement number 2";
choices[1]=new Array();
choices[1][0]="Incorrect answer";
choices[1][1]="Correct answer";
choices[1][2]="Incorrect answer";
choices[1][3]="Incorrect answer";
answers[1]=choices[1][1];

questions[2]="3) Statement number 3";
choices[2]=new Array();
choices[2][0]="Incorrect answer";
choices[2][1]="Incorrect answer";
choices[2][2]="Correct answer";
choices[2][3]="Incorrect answer";
answers[2]=choices[2][2];

questions[3]="4) Statement number 4";
choices[3]=new Array();
choices[3][0]="Incorrect answer";
choices[3][1]="Incorrect answer";
Choices[3][2]="Correct answer";
Choices[3][3]="Incorrect answer";
answers[3]=choices[3][2];

questions[4]="5) Statement number 5";
choices[4]=new Array();
choices[4][0]="Correct answer";
choices[4][1]="Incorrect answer";
Choices[4][2]="Incorrect answer";
Choices[4][3]="Incorrect answer";
answers[4]=choices[4][0];

questions[5]="6) Statement number 6";
choices[5]=new Array();
choices[5][0]="Incorrect answer";
choices[5][1]="Correct answer";
choices[5][2]="Incorrect answer";
choices[5][3]="Incorrect answer";
answers[5]=choices[5][1];

questions[6]="7) Statement number 7";
choices[6]=new Array();
choices[6][0]="Incorrect answer";
choices[6][1]="Incorrect answer";
choices[6][2]="Correct answer";
choices[6][3]="Incorrect answer";
answers[6]=choices[6][2];
=============== =============== =============== ==========

.... and the quiz_functions. js code is this:

=============== =============== =============== ==========

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by James Crooke ::
http://javascript.internet.com/misce...oice-quiz.html
Modified by: Marc Bertrand:: http://www.goalseek.net*/

var useranswers = new Array();
var answered = 0;

function renderQuiz() {
for(i=0;i<quest ions.length;i++ ) {
document.writel n('<p class="question ">' + questions[i] + ' <span
id="result_' + i + '"></span></p>');
for(j=0;j<choic es[i].length;j++) {
document.writel n('<input type="radio" name="answer_' + i + '"
value="' + choices[i][j] + '" id="answer_' + i + '_' + j + '"
class="question _' + i + '" onclick="submit Answer(' + i + ', this,
\'question_' + i + '\', \'label_' + i + '_' + j + '\')" /><label
id="label_' + i + '_' + j + '" for="answer_' + i + '_' + j + '"> ' +
choices[i][j] + '</label><br />');
}
}
document.writel n('<br><br><hr> <br><div id="anID">Clic k the button
<b>Show Score</b> to find your score.</div><p><hr><br> <input
type="submit" value="Show Score"
onclick="WriteS core()">&nbsp;& nbsp;&nbsp;<inp ut type="submit"
value="Reset Quiz" onclick="resetQ uiz(true)" /></p>');
}


function resetQuiz(showC onfirm) {
//if(showConfirm)
if(!confirm("Ar e you sure you want to reset your answers and start
from the beginning?"))
return false;
document.locati on = document.locati on;
}

function submitAnswer(qu estionId, obj, classId, labelId) {
useranswers[questionId] = obj.value;
answered++;
}

function WriteScore() {
/*if(answered != answers.length) {
alert("You have not answered all of the questions yet!");
return false;
}*/
questionCount = answers.length;
correct = 0;
incorrect = 0;
for(i=0;i<quest ionCount;i++) {
if(useranswers[i] == answers[i])
correct++;
else
incorrect++;
}
pc = Math.round((cor rect / questionCount) * 100);
DynWrite('anID' ,'You scored <b>'+ correct +' correct answers out of '
+ questionCount + '</b> or <b>' + pc + ' %</b>')

}

=============== =============== =============== ==========

Jan 16 '06 #1
1 2251
mb
Yes indeed. Thanks Lee.

Marc Bertrand

Jan 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
5372
by: Cameron | last post by:
I can't get images from remote machines to appear on my reports. The readme for reporting services SP1 says about external images "the report server uses the unattended execution account to retrieve the image." I have an image with a source of 'External' and I assign the Value to a URL with a table as follows - = First(Fields!URL.Value,...
0
2163
by: Sachy | last post by:
Hi, I have received following error in my ASP.NET application. Many of buttons on the different pages are generating this error. I am not sure what I did until this morning code was working fine. I have downloaded the Office updates and installed them. Rebooted my system. Now after few hours I am getting this error almost everywhere. I am...
9
6885
by: Charley Kyd | last post by:
I'm a newbie who needs advice about how to use external files of JavaScript code. I spent an hour this afternoon browsing through JavaScript books at the local book store. In about 15 different titles, I found a total of about five pages that covered js files. For all practical purposes, these pages said, "You can use js files. But we won't...
8
2567
by: David D. | last post by:
In html, one can say <script language="JavaScript" src="http://someCodeSnippet.js"> Is there any way to embed the included code snippet in a function (in the case where it is not already a function in the remote souce file)? - David D.
2
2278
by: Jim Adamson | last post by:
Hi I want to defer the call of an external .js file so that when the link in the page is clicked, the .js file is downloaded and included in the page. The link would also pass on some arguments to the function in the page. Once the .js file is successfully downloaded/included, I would then like to pass on the arguments from this function...
2
5308
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 Ask on...
20
11845
by: Mark Anderson | last post by:
Hi, I have this in an external JS library: ///////////////////////// function addMyEvent(){ var obj; if(document.attachEvent) { obj = document.getElementsByTagName('img'); for (i=0;i<obj.length;i++) { obj.attachEvent('ondrag', noDrag); }
2
6121
by: murthydb2 | last post by:
Hi My requirement is that i have to write a stored procedure in db2 and that will be executed in a batch file . Any system error or validation error that occurs inside the db2 sp during the execution need to be written in external flat file ( Log file to know the error ) . Is there anything similar in db2 like UTL_FILE in oracle...
3
7872
by: Abhinavnaresh | last post by:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Xml.Xsl.XsltException: Cannot find the script or external object that implements prefix 'counter'. Source Error: ...
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.