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

manipulating a URL-encoded string so it can be sent again 1

Status
Not open for further replies.

NewtownGuy

Technical User
Jul 27, 2007
146
US
Hello,

I originally posted this in the cgi-bin forum, where it was suggested I post it here.

I have a question about manipulating URL-encoded variables. I need to create a string that combines information from two successive invocations of the browser, where the second invocation adds additional information to the URL-encoded string from the first invocation. The ultimate string gets processed by a Perl script in cgi-bin. Information from the first invocation will be used many times, with different additional information being added to it during successive second invocations of the browser.

I have a custom application that needs to send a URL of the following form (this information will be used over and over):

Code:
[URL unfurl="true"]http://ip_address:8000/?value1=1234?value2=abcd[/URL]

to a browser, which will open index.html on the httpd server at ip_address:8000/

index.html does not need to respond to the variables sent to it, but it needs to be able to send them on to the httpd server, along with additional information, when the user pushes a button in index.html.

So, when a button is clicked, I want index.html to modify the URL that it received and to send the resulting string to the httpd server. I want to create a composite string of the following form including new information from that button:


Code:
[URL unfurl="true"]http://ip_address:8000/cgi-bin/script.pl?button_data=whatever?value1=1234?value2=abcd[/URL]

My question is how do I program index.html, in response to a button click, to extract the variables sent to it by the first invocation of the browser, add more text to the URL string it received including cgi-bin/script.pl and other variables, and to include the initial variables, all in the proper order for ultimate processing by a Perl script in cgi-bin ? I need successive button clicks to be able to reuse the initial information.

Thank you.

-- NewtownGuy
 
Hi

Not sure what you want... To access the query string in JavaScript use [tt]window.location.search[/tt].
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title></title>
<script type="text/javascript">
window.onload=function() {
  var list=document.getElementById('list')
  var pl=location.search.replace(/^\?/,'').split(/&/)
  for (var i=0;i<pl.length;i++) {
    var pa=pl[i].split(/=/,3)
    var ro=list.insertRow(list.rows.length)
    ro.insertCell(0).innerHTML=pa[0]
    ro.insertCell(1).innerHTML=pa.slice(1).join('=')
  }
}
</script>
</head>
<body>
<p>I received the following parameters in the URL :</p>
<table id="list">
<tr><th>Name</th><th>Value</th></tr>
</table>
</body>
</html>

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top