Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - How to pass a variable?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to pass a variable?

 Post Reply Post Reply
Author
phorne View Drop Down
Newbie
Newbie


Joined: 18 May 2003
Location: United States
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote phorne Quote  Post ReplyReply Direct Link To This Post Topic: How to pass a variable?
    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!

Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post 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")

Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
phorne View Drop Down
Newbie
Newbie


Joined: 18 May 2003
Location: United States
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote phorne Quote  Post ReplyReply Direct Link To This Post 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!!!

Back to Top
phorne View Drop Down
Newbie
Newbie


Joined: 18 May 2003
Location: United States
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote phorne Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.