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

Passing a variable in URL from button

Status
Not open for further replies.

nevets2001uk

IS-IT--Management
Jun 26, 2002
609
GB
I have a search engine working on my site now and currently pass the original search from page one to page two through the form POST method.

However I would rather pass the variable in the URL as I am allowing users to page results and bookmark searches. I have done this within my paging using the following code...

<a href=&quot;<% =strURL %>?search=<% =Server.URLEncode(searchstring) %>&page=<% =PageCurrent+1 %>&quot;>[Next
&gt;&gt;]</a>

This works correctly. How would I pass my original search when a button is clicked on a form? I tried...

<form action=&quot;search_results.asp?search=&quot; &<% =Server.URLEncode(PartNo) %> method=POST>

but this made no difference.

Any ideas?

Steve Gordon
 
Build up the url using

Request.ServerVariables (&quot;SCRIPT_NAME&quot;)



ooooooooooooooooooooooooh bugger.
 
You can also use

Request.ServerVariables(&quot;QUERY_STRING&quot;)

so you could use:

<form action=&quot;search_results.asp?<% =Request.ServerVariables(&quot;QUERY_STRING&quot;)%> method=POST>

or even:

<form action=&quot;<%=Request.ServerVariables(&quot;SCRIPT_NAME&quot;)&&quot;?&quot;& Request.ServerVariables(&quot;QUERY_STRING&quot;)%> method=POST>

(Note, the Request.ServerVariables(&quot;QUERY_STRING&quot;) does not includes the initial ?)
 
I'm a bit new to this and havn't been able to get those to work. Let me clarify the main problem.

I have a form with a text box and a button.

When the button is clicked the results page should be loaded and search_results.asp

This works at the moment but I pass the textbox value with the form and pick it up with requrest.form

I want to be able to create the following in the url when the button is clicked so that I can pick up the value of the search from there...

something like
Can I just put that into the address bar on a button click. From there i should be able to get it working.

You replys didn't seem to make any noticable changes.
 
If you want the search string to go in the URL, change the method of your form from POST to GET

eg.
<form action=&quot;search_results.asp?search=&quot; &<% =Server.URLEncode(PartNo) %> method=GET>

The GET method passes the form parameters into the URL.

But I am still not sure if this is what you want to do...???

You could try:

<input type=&quot;button&quot; name=&quot;search&quot; value=&quot;whatever&quot; onClick=&quot;Javascript:window.location.href('search_results.asp?<%=Request.form(&quot;search&quot;)%>';&quot;)

Is this more like what you are trying to do??
 
Ok you have a form. so why bother to use query strings?
Try to use a hidden field who stores the old search querry
<form action=&quot;search_results.asp&quot;>
<input type=hidden name=search value=<%=Request(&quot;search&quot;)%>>
</form>

or use Biffy13 ideea

________
George, M
 
Thanks everyone for your help. I have got it all working now. Ended up scrapping the form entirely as it really wasn't needed.

Ended up using a variation of Biffy13's idea and creating a vbScript sub for the onclick event of the button.

Cheers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top