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

How to construct a post string on submit? 1

Status
Not open for further replies.

ashorton

Programmer
Mar 1, 2001
24
GB
I have a placed a table in a form. The table behaves like a grid reading data to and from a javascript array.

The problem I have is when the form is submitted how can I get the browser to create a post string from the array rather than from the form.

I idea I have is to dynamical add hidden elements to the form for each item of data in the array. Then add data from the array into the hidden elements. I have not tried this yet so I do not know if it will work.

Any idea's for a simple method.

 
Hi ashorton,

The following example reads the values of a few arrays and builds it into a querystring.

Code:
<html>
<head>
	<title>Post Array</title>
	<script language=&quot;JavaScript&quot;>
		arr1 = new Array()
		arr1[0] = new Array('aa','ab','ac')
		arr1[1] = new Array('ba','bb','bc')
		arr1[2] = new Array('ca','cb','cc')
		
		function getQueryString() {
			qry = &quot;&quot;
			for (i=0;i<3;i++) {
				for (j=0;j<3;j++) {
					if (i==0 && j==0) { ch = '?' } else { ch = '&' }
					qry = qry+ch+&quot;arr&quot;+i+j+&quot;=&quot;+arr1[i] [j]
				}
				
			}
			alert(qry)
		}		
	</script>
</head>

<BODY onload=&quot;getQueryString()&quot;>
</body>
</html>

Don't know if this is exactly what you are thinking about, but you can use the principle anyhow I think. :p

Gtz,

Kristof -------------------
Check out my new site:

Any suggestions are more than welcome.
There's a LOT of work to do, so judge fairly. :)
 
Note that that's a GET string, not a POST. To generate a POST you need to move the values into hidden fields and submit a form. POST doesn't actually generate a &quot;string&quot; per-se, it creates data that has to be read by the program through it's standard input. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top