none
Need advice how to send variables when opening another page when user clicks image on current page RRS feed

  • Question

  • Hello All!

    I am very novice, but proud of what I've done so far! ;o)

    I have an aspx page (vegetables.aspx) that uses VB script to open a MySQL database, makes a query, and then displays the resulting recordset dynamically, without much code.

    That part is working great! I run a small farm and the recordset is returning a list of vegetables I am growing here. As I loop through the recordset, I use the vegetable variety name to dynamically display a picture of the vegetable as a column, followed by the full description of the variety. It does that for each record and loops till eof. Works nicely!

    Now what I want to do is to make it where someone can click on any of those vegetable variety pictures to bring them to a new page with more information about the variety they clicked on. I have the other page, details.aspx already created. It has my website's header, menu buttons...etc., I want it to dynamically create the content based on what vegetable variety more details was requested on. So I need to somehow send a variable (the vegetable variety clicked on) to details.aspx.

    I don't know of a way to do it by adding an <a href="details.aspx"> tag to my image tag... that wouldn't give me access to the variables I need from the details.aspx page

    I thought maybe I could use the onclick event of the image tag, so when someone clicks the image, it would fire the onclick event which I could easily pass the variable, vegetable variety name, to. I would think I could somehow load the details.aspx page from here, sending the variable so details.aspx would have access to it and then make a query to the db, displaying resulting more info about that variety, but when I looked up how to do it, I am finding a lot of conflicting information that has me all confused. I am using VBScript, and I know its running on the server because my MySQL database is on the server and its returning data. When I am searching online about the image onclick event, it says its client side code and it will only work on IE.

    So Experts.... what is the best way to code loading details.aspx when a user clicks on an image? It has to send the vegetable variety name to details.aspx so that details.aspx can display more information from the database about that particular variety, and it HAS to work on all major browsers.

    Here is a snippet of what my vegetables.aspx code is that displays my list. It can be viewed, at least for right now at www.abetterwayfarms.com/vegetables.aspx. btw... if you're wondering below why I didn't use a stored procedure when I call the recordset, I can't seem to get the syntax right, seems pretty strait forward, but I keep getting an error on syntax, that isn't the point right now though. ;o)  I can work on that later. ;o)

    ConnString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=my server name; PORT=3306; DATABASE=my db name; USER=ME; PASSWORD='my pw'; OPTION=3"

        'create an instance of the ADO connection and recordset objects
        Connection = Server.CreateObject("ADODB.Connection")
        rs = Server.CreateObject("ADODB.Recordset")

        'Open the connection to the database
        Connection.Open(ConnString)
       
       

        'Open the recordset object executing the SQL statement and return records
        rs.Open("SELECT P.Name, P.Variety, P.QuanityAvail, PD.FullDesc, PD.DateExpected FROM abwProduce P INNER JOIN abwProduceDetails PD ON P.Variety = PD.Variety AND P.Name = PD.Name", Connection)
        rs.movefirst()
        'First display the header for the table
        Response.Write("<table border=1 width=725px><tr><td width=100px>Click Pic for More Info</td><td width=575>Variety Description</td><td width=50px>Date Expected</td></tr>")
        'Now begin the dynamic code that will display a row for each record returned.
        Do While Not rs.eof
            strNameVariety = rs("Name").value & rs("Variety").value
            Response.Write("<tr><td width=100px><img src=files/vegetables/")
            Response.Write(strNameVariety & ".jpg")
            Response.Write("></td><td valign=top width=575px>")
            Response.Write(strNameVariety)
            Response.Write("<br>")
            Response.Write(rs("FullDesc").value)
            Response.Write("</td><td width=50px>")
            If rs("QuanityAvail").value > 0 Then
                Response.Write("Available Now")
            Else
                DtExpected = FormatDateTime(rs("DateExpected").value, DateFormat.ShortDate)
                Response.Write(DtExpected)
            End If
            Response.Write("</td></tr>")
            rs.movenext()
        Loop
        Response.Write("</table>")

      
        'Close database connection
        Connection.Close()
        Connection = Nothing
    %>
    Thursday, March 31, 2011 3:33 PM

Answers

  • You can pass simple variables as name=value pairs in the QueryString of the URL that calls the new page. See this page for examples using VBScript. QueryString can also be retrieved using other languages. Just substitute the appropriate syntax to retrieve the variables and their values.

    cheers,
    scott


    Please remember to "Mark as Answer" the responses that resolved your issue. It is common courtesy to recognize those who have helped you, and it also makes it easier for visitors to find the resolution later.
    Thursday, March 31, 2011 3:45 PM

All replies

  • You can pass simple variables as name=value pairs in the QueryString of the URL that calls the new page. See this page for examples using VBScript. QueryString can also be retrieved using other languages. Just substitute the appropriate syntax to retrieve the variables and their values.

    cheers,
    scott


    Please remember to "Mark as Answer" the responses that resolved your issue. It is common courtesy to recognize those who have helped you, and it also makes it easier for visitors to find the resolution later.
    Thursday, March 31, 2011 3:45 PM
  • YAY!!!! That worked!!!! THANK YOU SOOOOOOOOO MUCH!!!!  ;o)
    Thursday, March 31, 2011 3:59 PM