View Full Version : image checkbox add value to db.

08-03-2002, 03:06 AM
Ok, I'm trying to figure how It would be possible to firstly change and img from one to another and then send an on value to a db or text file which would check to see if it had been turned on each time the page loads and change the img accordingly.

I hope that I'm making sense, basically I'm trying to make an image checkbox which remembers if it is checked or not.

I've tried to change the image like this but it doesn't seem to work:
dim Img1
dim Img2
dim CurrentImg

Img1 = Server.MapPath(/off.png)
Img2 = Server.MapPath(/onn.png)

CurrentImg = Img1
Then in the <img> I used

<img src="<%=CurrentImg%>" OnMouseDown="<%=CurrentImg = Img2%>">


08-03-2002, 03:19 AM
I got the image to change using this

dim ThisUrl
ThisUrl = ""
dim img1
dim img2
dim currentimg
img1 = server.MapPath("off.png")
img2 = server.MapPath("onn.png")
currentimg = img1

if Request.QueryString("ch1") = "on" then
currentimg = img2
end if
and the <img>

<a href="<%=ThisUrl%>"><img src="<%=currentimg%>" border="0"></a>
But is there a way to do it without sending a querystring like that?

08-04-2002, 02:17 AM
One way, you could have a form with a hidden field, and post that - when you click the image, have javascript change the value of that (hidden) field - then you could get the value of the variable with Request.Form("myhiddenfieldname")


08-04-2002, 09:08 AM
Well, first off, are you trying to make an onmousedown event?

And OnMouseDown="<%=CurrentImg = Img2%>" will not work.

What you said is exactly this:

Dim StrA, StrB, StrAB

StrA = 1
StrB = 2

StrAB = StrA

Response.Write StrAB
Response.Write StrAB = StrB

The Answer is:
"1" from the first Response.Write.
"False" from the second Response.Write.

The answer is False for the second Response.Write, because 1 doesn't equal 2.

To get that code to work right, you'll need to add one more line of code.

Dim StrA, StrB, StrAB

StrA = 1
StrB = 2

StrAB = StrA
Response.Write StrAB
StrAB = StrB
Response.Write StrAB

This code Returns:
"1" from the first Response.Write
"2" from the second Response.Write

For your first image tag, why not just do this:

<img src="<%=Img2%>" OnMouseDown="<%=Img2%>">

08-04-2002, 10:30 AM
uh? hmm....Well Morgoth that is clever, but I to dim to figure how I am to relate that to my problem. ;)

Anywho I'm giving up on this. Thanx anyways, maybe I'll try again in the not to distant future.


08-05-2002, 08:51 AM
Oh... so you wish not to have a querystring, eh?
Why not send it as a form. (Method="post")
Then you can do something like:
String = Request.Form("ch1")

Help now?

08-05-2002, 12:27 PM
Is there a way to change the image without refreshing the page?
I know how to do it in js but I'd like to be able to do it in asp to be different.

Or should I just stick to browser scripting for this sought of thing?

08-06-2002, 12:26 AM
Without refreshing the page, you have to use javascript to do it, since you aren't sending/retrieiving any information to/from the server.

08-06-2002, 10:17 AM
ASP is server side, therefore it is not run in real time.