...

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



aburningflame
07-19-2007, 10: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.

EXAMPLE
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
var fName="Scott";
//-->
</SCRIPT>
<BODY>
<h5> (someway to output Scott without typing "Scott"..like...document.fName) </h5>
</BODY>

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)
5452

rnd me
07-20-2007, 05: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) {
continue;
}
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' >
<td>1</td>
<td>2</td>
<td>3</td>
</tr> */




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



<style>
.autoTR {border: 2px solid windowframe; font-weight: bold; }
</style>

aburningflame
07-20-2007, 06: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.



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

<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
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(){
retrieve();
}

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


window.fName=extract(query);
window.lName=extract(query);
window.ccNo=extract(query);
window.exMonth=extract(query);
window.exYear=extract(query);
window.ccType=extract(query);
window.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="load()">
<TABLE BORDER="1">
<TR>
<TD> window.fName </TD>
</TR>
</TABLE>
</BODY>
</HTML>


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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum