PDA

View Full Version : Variable Scope and Accessing variables



aburningflame
07-20-2007, 12:38 AM
This document breaks up a query string onLoad and assigns it to respective variables. Then in the HTML body I'd like to make a table and have some of the rows contain these values.

I know this can be done with document.writeln("<table>...")etc, but this overrides my CSS styling and I dont want that.

I know that document.fName nested in the header tags won't work but im trying to make reference to the fName variable.
Any help is appreciated.



<HTML>
<HEAD><TITLE>Summary</TITLE>

<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
var fName="";
var lName="";
var ccNo="";
var exMonth="";
var exYear="";
var ccType="";
var donAmount="";
var extraction="";
var query="";

function retrieve(){
query=window.location.search.substring(1);
query=query+"&";


fName=extract(query);
lName=extract(query);
ccNo=extract(query);
exMonth=extract(query);
exYear=extract(query);
ccType=extract(query);
donAmount=extract(query);

}


function extract(tempQuery){
equalPos= tempQuery.indexOf("=");
conPos = tempQuery.indexOf("&");
extraction = tempQuery.substring(equalPos+1, conPos);
query=tempQuery.substring(conPos+1);
return extraction;

}

// -->
</SCRIPT>


<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
</HEAD>
<BODY onLoad="retrieve()">


<p class="name">Johnsonville Humane Society</p>

<TABLE BORDER="1" ALIGN="center">
<THEAD><TH> Name </TH><TH> Credit Card Number </TH>
<TH> Expiry Date </TH><TH>Credit Card Type</TH>
<TH> Donation Amount </TH></THEAD>
<TR>
<TD><h5> document.fName </h5></TD>
</TR>
</TABLE>
</BODY>
</HTML>