Click to See Complete Forum and Search --> : Going from document.write--> HTML and JS variables


mikehump
05-05-2003, 01:17 PM
Hi guys,

I would like to redo my web page using standard HTML Markup.

What I have now is a js file that is loaded at the top of the web page:

<script language="JavaScript" src="JS_Scripts/02_Baptism.js"></script>
<SCRIPT language=JavaScript1.2 type=text/javascript>
<!--
parseData_PrintHeader();
// -->
</SCRIPT>
and has the following:

start of function:


function parseData_PrintHeader() {
// grab search string

var rawData = unescape(location.search.substring(1))

if (rawData) {

// Divide long string into array of name/value pairs.
var srchArray = rawData.split("&")
var tempArray = new Array()
for (i = 0; i < srchArray.length; i++) {
// Divide each name/value pair temporarily into a two-entry array.
tempArray = srchArray[i].split("=")
// Use temp array values as index identifier and value.
//e.g. tempArray[0] = LevelOneScore, tempArray[1] = it's value
incomingData_Baptism[i] = tempArray[1]
// This has the score values in them: results[tempArray[0]]
//testscores[i] = results[tempArray[0]];
// alert("testscores[i] = " + testscores[i]);
}
Baptism_NoCorrect = incomingData_Baptism[0];

}


document.write("<table width='640' align='center' style='background-color: Black; color: White;'><tr><td><CENTER><H2><font face='Verdana, Arial, Helvetica, sans-serif'>Title Page</H2><BR><H3>Level 3 - Subtitle</H3></CENTER><p align='left'></p><ul><font size='-1'><b>CONGRATULATIONS!</b> You have made it past level 2, <b>Level 2</b> by geting <b>" + Baptism_NoCorrect + " out of 30</b> ....... "); etc.

end of function

After converting it to HTML Markup, I'm trying to figure out why this doesn't work:

<font size="-1"><b><font face="Verdana, Arial, Helvetica, sans-serif">CONGRATULATIONS!</font></b><font face="Verdana, Arial, Helvetica, sans-serif"> You
have made it past level 1, <b>The Sacraments in General</b> by geting --<b>

<script language="JavaScript1.2" src="JS_Scripts/02_Baptism.js">
<!--
InitialLevel_NoCorrect
// -->
</script>

out of 10</b> correct for a score of <b>

<script language="JavaScript1.2" src="JS_Scripts/02_Baptism.js">
<!--
FormatNumber(InitialLevel_Score.toString());
// -->

</script>
</b></font></font></p>
<p align="left"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Game Summary:
You have reached level 2 and answered a total of <b>

<script language="JavaScript1.2" src="JS_Scripts/02_Baptism.js">
<!--
TotalCorrect;
// -->
</script>
</b> out of 10 possible questions.</font></p>


The text shows up OK, and I get no Javasript errors but the Javascript variables
don't show up at all.


Any help would be appreciated,

Mike
:(

havik
05-05-2003, 02:04 PM
That's because this:

<script language="JavaScript1.2" src="JS_Scripts/02_Baptism.js">
<!--
InitialLevel_NoCorrect
// -->
</script>

and this:

<script language="JavaScript1.2" src="JS_Scripts/02_Baptism.js">
<!--
TotalCorrect;
// -->
</script>

aren't the proper ways to write your javascript variables. You'll still need to use document.write to output them.

ie:
document.write(' ' + TotalCorrect + ' ');

Havik

mikehump
05-05-2003, 03:29 PM
Thanks Havik,

Thanks for your suggestion. It is a step closer, but no variables are being output. I put a alert debug statement to see if it was being hit and it wasn't. Take a look:

//At the top of the page:

<script language="JavaScript" src="JS_Scripts/02_Baptism.js">
<!--
parseData_PrintHeader();
// -->
</SCRIPT>
.
.
.
<p><font size="-1"><b><font face="Verdana, Arial, Helvetica, sans-serif">CONGRATULATIONS!</font></b><font face="Verdana, Arial, Helvetica, sans-serif"> You
have made it past level 1, <b>The Sacraments in General</b> by geting --

<script language="JavaScript1.2" src="JS_Scripts/02_Baptism.js">
<!-- NOT HIT
alert("InitialLevel_NoCorrect = " + InitialLevel_NoCorrect);
document.write('' + InitialLevel_NoCorrect + '');
// -->
</script>

out of 10 correct for a score of --<b>

Once I divide the long string into array of name/value pairs by calling the function parseData_PrintHeader() I can't output it?


Screen Output:

CONGRATULATIONS! You have made it past level 1, The Sacraments in General by geting -- out of 10 correct for a score of --

Game Summary: You have reached level 2 and answered a total of -- -- out of 10 possible questions.

Your Score for for all levels played is now -- " .


Any ideas? Thanks for helping me.

Mike

havik
05-06-2003, 03:25 PM
Well, I'd have to see the .js file your including to debug any code within there.

For now try the second script without the src="JS_Scripts/02_Baptism.js"

So that section should look like this:

<script language="JavaScript1.2">
<!--
alert("InitialLevel_NoCorrect = " + InitialLevel_NoCorrect);
document.write('' + InitialLevel_NoCorrect + '');
// -->
</script>

FYI: Browsers lower than NS 4 and IE 4 will ignore the code (because JavaScript1.2 was specified)

In case, are the variables your trying to output arrays? Because then you'd need to output them in a special way.

Havik

mikehump
05-07-2003, 12:09 AM
havik said:

>>Well, I'd have to see the .js file your including to debug any code within there.

Hi havik,

I agree with your assessment. I guess I thought I could figure it out on my own.

I've documented the top section with Javascript comments.

I hope this helps.

Thanks,

Mike

havik
05-07-2003, 05:09 PM
Don't call the 02_Baptism.js file twice. So remove that first like the following:

<script language="JavaScript1.2">
<!--
alert("InitialLevel_NoCorrect = " + InitialLevel_NoCorrect);
document.write('' + InitialLevel_NoCorrect + '');
// -->
</script>

Also, in the 02_Baptism.js file, remove the var keywords from the InitialLevel_NoCorrect, InitialLevel_Score, and any other variables you need to write out.

FYI:

Lets say test.js had a variable you needed to access, then the following won't work (for reasons which I'm unaware of):
<script ... src="test.js">
document.write(' + theneededvariable + ');
</script>

Havik

mikehump
05-07-2003, 11:47 PM
HI Havik,

I think that was it.

What I did:

I removed the var definitions from the *.js files and moved
them to within the

cfm code like:

<script language="JavaScript1.2">
<!--
parseData();
var InitialLevel_NoCorrect;
document.write('' + InitialLevel_NoCorrect + '');
// -->
</script>


I also had to call parseData() NOT from the top of the web page but within the first variable I wanted to print out with the document.write function.

The other one only needed this:

<script language="JavaScript1.2">
<!--
var InitialLevel_Score;
document.write(' ' + FormatNumber(InitialLevel_Score.toString()) + ' ');
// -->
</script>

without the function call.

I have 10 web pages to change but have done two already and I think it will work.....a few Hail Mary's would hurt either :D

Thank-you very much for your help.

If you give me your first and last name I will be sure to give you the desired credit when my program goes on-line.

You can reply at:

mikehumphrey@rcn.com

I think this will, hopefully, be the end of this thread.

Problem solved! :)

If you want to see the current status of the project you are more than welcome:

Who Wants To Be A Catholic

Registered Version:
http://www.cpats.org/whowantstobe/

Non-Registered Start:
http://www.cpats.org/whowantstobe/01_index_wwbac.cfm

Mike Humphrey
Catholic Apologist
http://www.cpats.org
"Promoting Catholic Apologetic support groups loyal to the Magisterium"
Question and Answer Knowledgebase:
http://www.cpats.org/CPATSAnswerDirectory/CPATS_CATQs.cfm

havik
05-08-2003, 09:51 AM
I thought that'd be the problem, because the .js file was coded without any visible errors.

Havik