View Full Version : UGH NEED HELP..so stuck :(

07-19-2007, 11:27 PM
Alright well im doing a college project and were supposed to make a website.
I have a site that takes input on one form and then opens another page.

This other page has javascript code that disassembles the query string and assigns the values to variables. Basically I wanna know if there is a way to access a variable in the head tag from html in the body tag.

var fName="Scott";
<h5> (someway to output Scott without typing "Scott"..like...document.fName) </h5>

I want to make a table in the body tag using HTML because using javascript overwrites the css rendering. I want that table to use the values from the previously declared variable. Please view the attachment and HELP.
Thanks so much in advance.
(I've spent like an hour researching this and can't find anything. Apparently when a variable is declared globally its scope includes the whole document...im guessing i could access it while in the body tags)

rnd me
07-20-2007, 06:20 AM
var in the head should survive into to body. you could add "window." before everything if in doubt.

you could also plant this in your body; it will provide json of the querystring via it's args property:

function sQS() {
var allem = [];
var RxUrl = new RegExp(/^[^\?]+\??/);
var RxQsSplit = new RegExp(/[;&]/);
var RxValRep = new RegExp(/\+/g);
var Params = {};
var cItem = window.location.toString();
var queryURL = cItem.replace(RxUrl, "");
var Pairs = queryURL.split(RxQsSplit);
var mx = Pairs.length;
for (var i = 0; i < mx; i++) {
var KeyVal = Pairs[i].split("=");
if (!KeyVal || KeyVal.length != 2) {
var key = unescape(KeyVal[0]);
var val = unescape(KeyVal[1]);
val = val.replace(RxValRep, " ");
try {
Params[key] = eval(val);
} catch (ee) {
Params[key] = val;
var filecache = cItem;
var srcInfo = {file:filecache, bootTime:new Date, urlSearch:queryURL, args:Params};
return srcInfo;

// this array can then be converted to a table:

function obVals(ob) {
var r = [];
var i = 0;
for (var z in ob) {
if (ob.hasOwnProperty(z)) {
r[i++] = ob[z];
return r;

Array.prototype.toTR=function () {
return "\n<tr class='autoTR' >\n" + wrapHT(this, "td") + "</tr>\n";

Array.prototype.group=function (f) {
mx = this.length;
var r = [];
for (z = 0; z < mx; z++) {
if (this[z]) {
r[r.length] = f(this[z], this, z);
return r;

function wrapHT(r, tg) {
var tt = [];
tt[0] = "<" + tg + ">";
tt[3] = "</" + tg + ">\n";
tt[2] = r.join(tt[3] + tt[0]);
return tt.join("");

// ------------------------

//ex: url=xxx.com?a=1&b=2&c=3

var qsOb= sQS().args //[{a:1},{b:2},{c:3}]
res=qsOb.group(function(o){return obVals(o)}).toTR() /* returns:

<tr class='autoTR' >
</tr> */

Use CSS classes to preserve formatting.
(in the head section)

.autoTR {border: 2px solid windowframe; font-weight: bold; }

07-20-2007, 07:11 AM
First of all Id like to say thanks for the response.
Anyways I think planting that in my body is a little to advanced.
but adding window. before everything seems a little easier. I still dont get how to implement this.


var window.fName="";
var window.lName="";
var window.ccNo="";
var window.exMonth="";
var window.exYear="";
var window.ccType="";
var window.donAmount="";
var window.extraction="";
var window.query="";

function load(){

function retrieve(){



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


// -->

<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<BODY onLoad="load()">
<TD> window.fName </TD>

Im really not sure if I can do what I wanna do this way.