Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post

    image checkbox add value to db.

    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:
    Code:
    <%
    dim Img1
    dim Img2
    dim CurrentImg
    
    Img1 = Server.MapPath(/off.png)
    Img2 = Server.MapPath(/onn.png) 
    
    CurrentImg = Img1
    %>
    Then in the <img> I used
    Code:
    <img src="<%=CurrentImg%>" OnMouseDown="<%=CurrentImg = Img2%>">
    Omnis mico antequam dominus Spookster!

  • #2
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    I got the image to change using this
    Code:
    <%
    dim ThisUrl
    ThisUrl = "http://127.0.0.1/m5/personal/chbx/chbx.asp?ch1=on"
    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>
    Code:
    <a href="<%=ThisUrl%>"><img src="<%=currentimg%>" border="0"></a>
    But is there a way to do it without sending a querystring like that?
    Omnis mico antequam dominus Spookster!

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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")

    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #4
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Well, first off, are you trying to make an onmousedown event?

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

    What you said is exactly this:
    Code:
    <%
    Dim StrA, StrB, StrAB
    
    StrA = 1
    StrB = 2
    
    StrAB = StrA
    
    Response.Write StrAB
    Response.Write StrAB = StrB
    %>
    The Answer is:
    "1False"
    "1" from the first Response.Write.
    And
    "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.
    Code:
    <%
    Dim StrA, StrB, StrAB
    
    StrA = 1
    StrB = 2
    
    StrAB = StrA
    Response.Write StrAB
    StrAB = StrB
    Response.Write StrAB
    %>
    This code Returns:
    12
    "1" from the first Response.Write
    And
    "2" from the second Response.Write


    For your first image tag, why not just do this:
    Code:
    <img src="<%=Img2%>" OnMouseDown="<%=Img2%>">

  • #5
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

    Mike..
    Omnis mico antequam dominus Spookster!

  • #6
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    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?

  • #7
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    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?
    Omnis mico antequam dominus Spookster!

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Without refreshing the page, you have to use javascript to do it, since you aren't sending/retrieiving any information to/from the server.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #9
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    ASP is server side, therefore it is not run in real time.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •