Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asign vars from external file

Status
Not open for further replies.

dakoz

Programmer
Feb 2, 2002
74
hi all i have the following

<script>

var objXmlHTTP,objXmlDOM;
var aQuest;
var aAnswer = new Array(); //
var aSelected = new Array();
var count = 0;
var ansSel = 0;
var timerID;
var radIndex = -1;

var ExamDuration = 5 * 60 ;
var showtimer = 1
var NoQ = 10


how can these 3 last variables be load the from an xml file such as

<?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-7&quot;?>
<data>
<QUESTIONS>10</QUESTIONS>
<TIMER>1</TIMER>
<DURATION>5 * 60</DURATION>



<question id=&quot;1&quot;>
<qtext>Ðïéüò åßíáé ï áñéèìüò ôùí ãíùóôþí ÷çìéêþ óôïé÷åßùí ùò ôï 1997</qtext>
<choices>
<choice>120</choice>
<choice>112</choice>
<choice>130</choice>
<choice>92</choice>
</choices>
<answer>2</answer>
</question>
<question id=&quot;2&quot;>
<qtext>Ðïéü ÷çìéêü óôïé÷åßï åéíáé õãñü;</qtext>
<choices>
<choice>Âñþìéï</choice>
<choice>Áæùôï</choice>
<choice>ÍÜôñéï</choice>
<choice>×áëêüò</choice>
</choices>
<answer>1</answer>
</question>
</data>

can this be done?
 
Yes you can call a .js file from an external source
do this:

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<script language=&quot;JavaScript&quot;>
var ExamD = 5 * 60 ; //these 3 can be put in a src file
var showtimer = 1; //and called from the server side
var NoQ = 10; //using &quot;src=&quot;
function fill_data() {
document.write(&quot;<QUESTIONS>&quot;+NoQ+&quot;</QUESTIONS>&quot;+&quot;<br>&quot;);
document.write(&quot;<TIMER>&quot;+showtimer+&quot;</TIMER>&quot;+&quot;<br>&quot;);
document.write(&quot;<DURATION>&quot;+ExamD+&quot;</DURATION>&quot;+&quot;<br>&quot;);
}
</script>

</head>
<body>
<script language=&quot;JavaScript&quot;>
fill_data();
</script>

</body>
</html>

2b||!2b
 
Sorry,

Meant to include this:
Between &quot;header tags&quot; use:
<script type='text/javascript' src='x_var.js'></script>

Where &quot;x_var.js&quot; is your file name.


2b||!2b
 
yes this can be done...

but the xml is an existing file.. i dont want to write vars in an XML file... maybee i first discription was not very clear.


Look i have a file called quiz.html which has a Javascript inside.. this javascript loads and external XML File which contains all the answers and questions of the quiz.

in the javascript i declare the following options at the beginning.


<script>

var objXmlHTTP,objXmlDOM;
var aQuest;
var aAnswer = new Array(); //
var aSelected = new Array();
var count = 0;
var ansSel = 0;
var timerID;
var radIndex = -1;

var ExamDuration = 5 * 60 ;
var showtimer = 1
var NoQ = 10

i want the last 3 to be loaded from the XML File that i store my question and answers. The xml file looks like :

<?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-7&quot;?>
<data>
<question id=&quot;1&quot;>
<qtext>Ðïéüò åßíáé ï áñéèìüò ôùí ãíùóôþí ÷çìéêþ óôïé÷åßùí ùò ôï 1997</qtext>
<choices>
<choice>120</choice>
<choice>112</choice>
<choice>130</choice>
<choice>92</choice>
</choices>
<answer>2</answer>
</question>
<question id=&quot;2&quot;>
<qtext>Ðïéü ÷çìéêü óôïé÷åßï åéíáé õãñü;</qtext>
<choices>
<choice>Âñþìéï</choice>
<choice>Áæùôï</choice>
<choice>ÍÜôñéï</choice>
<choice>×áëêüò</choice>
</choices>
<answer>1</answer>
</question>
</data>


i want the 3 variables to be on the top of the XML File looking like this

<QUESTIONS>10</QUESTIONS>
<TIMER>1</TIMER>
<DURATION>5 * 60</DURATION>

and loaded from the JavaScript.

In other word i want to channge the XML each time without having to modify the JavaScript
 
I don't know dakoz.
Let's see if the javascript vasity can help...



2b||!2b
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top