Forum Moderators: phranque

Message Too Old, No Replies

transfer a value from onclick to asp code

onclick value to asp

         

Zincoianoid

5:07 pm on Nov 14, 2003 (gmt 0)

10+ Year Member



I have a page which uses the onclick command:

<a href='#' onClick='go("products.asp");return false;'>Products</a>

I want to use multiples of it as menu choices, no problem there.
But each choice as yet only takes you to a page. I want it to choose the same page but have a variable set so that the asp code on the page can tell which choice it was.
It is part of a simple shopping cart and leaving the page causes the cart to reset (another thing I have to look at).
I have used a form and it works as far as the variable but the cart resets to no product.

Also, my old html book does not mention onclick. What version of code is this command and where can I find good online references to it?

Hope there is enough here to go by.
thanks for your efforts.

shasan

9:03 pm on Nov 14, 2003 (gmt 0)

10+ Year Member



I'm a little confused. Just to repeat what you said:

You want all requests to go to the same asp page that will change depending on what the request was for.

Is this correct?
If so, you can set up the ASP page to look for the variable (i think you already knew that). And for the menu items you should be able to get away with something like this:

<a href='#' onClick='go("mainpage.asp?page=products");return false;'>Products</a>

HTH

Zincoianoid

8:53 pm on Nov 15, 2003 (gmt 0)

10+ Year Member



I tried it but it does not seem to work. May not have set it right.
This may help you to understand my problem.

this is the head.asp file

<p>[&nbsp;<a href='#'
onClick='go("/index.asp");return false;'>Home</a>&nbsp;¦&nbsp;<a href='#'

onClick='go("products.asp?choose=bulbs");return false;'>bulbs</a>&nbsp;¦&nbsp;<a href='#'
onClick='go("products.asp?choose=wipers");return false;'>wipers</a>&nbsp;¦&nbsp;<a href='#'
onClick='go("products.asp?choose=oil");return false;'>oil</a>&nbsp;¦&nbsp;<a href='#'

onClick='go("cart.asp");return false;'>Show Cart</a>&nbsp;]

this is the products asp file:

<!--#include file='db.asp'-->
<!--#include file='head.asp'-->

*** notice the link to head.asp which shows this menu on the products page

<title>Auto Supplies</title>

<table border=0 width=500 cellpadding=0 cellspacing=0>
<%

' Value of text input field "choose"

myquery = Request.Form("choose")
myquery = "exec q"
if myquery = "exec q" then myquery = "exec qlistall"

' executing stored procedure

set rs = conn.execute(myquery)
do while not rs.eof

*** end of file

As you can see I need to get the value of 'choose' into the asp code. I may be missing the obvious, who knows.

Any help is welcomed.

shasan

6:55 am on Nov 16, 2003 (gmt 0)

10+ Year Member



hmm.. I don't know ASP at all, but the logic should work.

what does Request.Form do?

The variable is being passed in the URL, not as part of the form. So I don't think Request.Form is the correct function to use.

Can you try it without the Request.Form? Sorry, I'm a PHP guy.

Zincoianoid

10:55 pm on Nov 18, 2003 (gmt 0)

10+ Year Member



what does Request.Form do?

Its asp's way of taking the value set in a form and bringing it to an asp variable.

graywolf

3:00 am on Nov 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think you want something like this


select case myquery

case 1
do thing a
case 2
do thing b
case 3
do thing c
case else
do something different

end select

It takes the the place of the multiple if statments and is a little easier to read than "ifelse" statements. If this doesn't help you may want to try the ASP Forum.

shasan

3:48 am on Nov 19, 2003 (gmt 0)

10+ Year Member




Its asp's way of taking the value set in a form and bringing it to an asp variable.

Yeah, see, the value wasn't being set in a form. graywolf's method should just pick up the variable that was passed. should work.

figment88

3:53 am on Nov 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if you are just going to paramaterize the target URL, there is no reason to use on onclick handler just put in in the href

<a href='#' onClick='go("mainpage.asp?page=products");return false;'>Products</a>

is simpler as

<a href='mainpage.asp?page=products'>Products</a>

txbakers

3:14 pm on Nov 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



is simpler as

<a href='mainpage.asp?page=products'>Products</a>

Simpler and much better coding for all browsers. Some browsers won't like the <a href="#"> with an onClick.

Iguana

3:33 pm on Nov 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Zincoianoid

You try to pick up the parameter as

myquery = Request.Form("choose")

but the paramter is passed in the query not via a form. You need:

Request.QueryString("choose") or just Request("choose")