Print Page | Close Window

How to pass a variable?

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=3378
Printed Date: 29 March 2026 at 5:01pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: How to pass a variable?
Posted By: phorne
Subject: How to pass a variable?
Date Posted: 08 June 2003 at 6:18am

Only thing worse than my programming ability is the simple ability to ask the right question!!

Yesterday I got the code to display records from queries from a Access database - thanks!

Now I want to use a form to get a variable and pass that on to select the query to use.

The select code that worked:

strSQL = "SELECT * FROM Bandits order by [6/5/03];"

Now I want to replace Bandits with a variable I select from a dropdown list:

  <FORM>
    <SELECT NAME="Select1" SIZE="1">
    <OPTION VALUE="bandit">Bandits</OPTION>
    <OPTION VALUE="masters">Masters</OPTION>
    <OPTION VALUE="Pro">Pro</OPTION>
    </SELECT>
 <INPUT TYPE="SUBMIT" NAME="Submit1" VALUE="Show Division"></FORM>

I don't understand how to get the variable and then get it in the select string...

Thanks in advance for the help!




Replies:
Posted By: WebWiz-Bruce
Date Posted: 08 June 2003 at 6:54am

If the form is submit to the server using the post method use:-

myVariable = Request.Form("Select1")

Change Select1 to the name of your form property you want to read in.

If using the get method to submit the forum use:-

myVariable = Request.QueryString("Select1")



-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: WebWiz-Bruce
Date Posted: 08 June 2003 at 6:55am
You may also want to change the name of the submit button so that each form object has a different name or you may get conflicts.

-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: phorne
Date Posted: 08 June 2003 at 7:14am

Which should I use - a get or post??

And it looks like it will work better if I have the form on one page and pass the variable to the page I use to display the data.

Can I have a form on one page and then pass the variable to the next??

For example - I have this form on a select.htm page

  <FORM ACTION="display_select.asp" METHOD="Post">
  <P>
    <SELECT NAME="selectdiv" SIZE="1">
    <OPTION VALUE="Bandits">Bandits</OPTION>
    <OPTION VALUE="Masters">Masters</OPTION>
    </SELECT><INPUT TYPE="SUBMIT" NAME="selectdiv"
    VALUE="Select Division"></P></FORM>

Now I want selectdiv to be passed to the display_select.asp page.

This may not be the best way to do it - but I understand it! Should be clear I am just not good at this stuff!!!



Posted By: phorne
Date Posted: 08 June 2003 at 7:21am

And a follow up question..

Would it be better to put the dropdown box on the same page?

If so do you use a form or another method - if I use a form how do I code it to get it in the middle of the asp code? The code I use to display the records is:

Do While not rsevent.EOF
 'Write the HTML to display the current record in the recordset
 Response.Write ("<br>")
 Response.Write (rsevent("Inex")) 

  Response.Write ("&nbsp;&nbsp;&nbsp;")
 Response.Write (rsevent("lastname"))
 Response.Write ("&nbsp;&nbsp;&nbsp;")
 Response.Write (rsevent("division"))
 Response.Write ("&nbsp;&nbsp;&nbsp;")
 Response.Write (rsevent("car"))
 Response.Write ("&nbsp;&nbsp;&nbsp;")
 Response.Write (rsevent("6/5/03")) 


 
 'Move to the next record in the recordset
 rsevent.MoveNext

Loop



Posted By: Mart
Date Posted: 08 June 2003 at 7:31am

Get and Post is up to you, get method will pass variables like this: page.asp?select1=hello. Post does the same thing but you can't see it in the URL.

Martin



Posted By: WebWiz-Bruce
Date Posted: 08 June 2003 at 8:35am

Post method is more secure and you can pass more data so use that.

It doesn't have to be the same page you can have the form submit to a completly different page.



-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net