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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to pass parseSearchString() variables into a table

Status
Not open for further replies.

gronsky

Technical User
Feb 8, 2002
36
0
0
US
It's me again.

I have a form in which after the inputs are validated they are then to be passed into a new page. I didn't like the look of the output, ie;

name = John
address = 1234 Some St.

I would like some alignment;

name = John
address = 1234 Some St.

The original function was this;
Code:
function parseSearchString()
{
	var pairs=unescape(location.search.substring(1).replace(/\+/g," ")).split('&');
	for (var i=0;i<pairs.length;i++){
		var pair = pairs[i].split('=');
		this[pair[0]]=pair[1];
	}
}
var search = new parseSearchString();

//this will output all the passed variables
document.write(&quot;These are the variables passed:<br />&quot;);
for (o in search) document.write(o + &quot; = &quot; + search[o]+&quot;<br />&quot;);

I tried to modify it so that the output is written in a table. (see below)

Being a newbie in javascripting I'm lost.
Can anybody help?????????

Thanks in advance


Code:
<html><head>
<title></title>
<script type=&quot;text/javascript&quot;>
//<![CDATA[
function parseSearchString()
{
	var pairs=unescape(location.search.substring(1).replace(/\+/g,&quot; &quot;)).split('&');
	for (var i=0;i<pairs.length;i++){
		var pair = pairs[i].split('=');
		this[pair[0]]=pair[1];
	}
}
var search = new parseSearchString();

document.write(&quot;These are the variables passed:<br />&quot;);
document.write (&quot;<table width='260' border='1'>&quot;)
for (o in search) document.write(&quot;<tr><td align='right'>&quot; + o + &quot;=&quot; + &quot;</td>&quot;
document.write (&quot;<td align='left'>&quot; + search[o]+ &quot;</td></tr>&quot;); }
document.write (&quot;</table>&quot;);
//]]>
</script>
</head><body></body></html>
 
Modify your &quot;
Code:
for (o in search)
&quot; line to read:

Code:
for (o in search) { document.write(&quot;<tr><td align='right'>&quot; + o + &quot;=&quot; + &quot;</td>&quot;);

And all should work.

You were missing an open brace '{' and close bracket ')'.

Hope this helps!

Dan
 
Thanks for the reply BillyRayPreachersSon,

It Works!

I added the '{' and ')' and also a ';'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top