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

How do I put a value in a querie string? 1

Status
Not open for further replies.

engcomp

Programmer
Jun 18, 1999
66
AU
I want to pass the value of two variables to a cgi task thus:

/domain/cgi-bin/task.cgi?name=realname&address=realaddress

var realname=GetCookie(name);
var realaddress=GetCookie(address);

How do I put the values of those vars into the querie string? As written, the task gets "realname" literally. It's probably something very simple, like putting between %signs. Please don't laugh at my ignorance.

Thank you, Helmut
 
I'm going to assume you'd like to do this in Javascript as that's what your code currently looks like. If I am incorrect, please forgive me.

You can use this function and alter any information you'd like. This assumes that you're only asking for the Realname and Realaddress variables. First, since spaces are bad in URLs, we convert these to a + sign (which will be converted back later), then we actually send the information on to the server.

Let me know if you'd like this explained in further detail.

Code:
function submitme()
{
var realname = GetCookie(name);
var realaddress = GetCookie(address);
var astr= realname.split(" "); //split the realname on spaces
var name = astr.join("+"); //Join them together on a + sign
var acity= realaddress.split(" "); //split the realaddress on spaces
var addr = acity.join("+"); //join them together on a + sign

var myactionurl = "[URL unfurl="true"]http://www.domain.com/cgi-bin/task.cgi?name="[/URL] + name + "&address=" + addr;

document.findus.action = myactionurl;
document.findus.method = "get";
document.findus.submit();
return true;

}

After that (and other Javascript checks if necessary), you'll only want to have the following in the HTML page if you're submitting other form data. No other information is necessary since we're dynamically assigning the other pieces in the submission Javascript above.

Code:
<form name=myform>
 
Dear Rieekan

WOW - I only posted the question a few minutes ago.

1. Yes, Javascript is my preferred language.

2. No - no further explanation is necessary because you set out every required factor so well even I can understand it (except document.findus - what's that?).

3. The HTML <form> code is missing, but I think I can handle that part.

Thank you very, very much.
Helmut
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top