Add a button to an ASP page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • colinod
    Contributor
    • Nov 2007
    • 347

    Add a button to an ASP page

    I really need some help!!!!!!

    I look after a website for my company www.yaketyyak.c o.uk as you will see we have a large list of actors on the site that we look after, each actor has their own id number.

    What i need is to be able to add a button to each artists own page that will add them to a shopping cart type page that a user can then email a link to.

    I only have asp available and am sure it is possible as i have seen it on anther website that does the same thing its here http://www.meetthejoneses.co.uk/

    i am not bery good with asp and could really do with some simply put advice nothing too technical please
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    The simplest asp solution would be to add the artist ID to a session-level variable every time you click the button. When you open the "shopping list" you need to open up the session-level variable and divide it up. Does this make sense? I know this isn't a thorough explanation at all, please let me know what parts I should explain better.

    Jared

    Comment

    • colinod
      Contributor
      • Nov 2007
      • 347

      #3
      Hi

      that seems perfect, i just dont know how to use session variables or how to split them or write to them when you click a button, so basically all of the above!!!!!

      Sorry but my knowledge of asp only goes as far as pulling info from a database

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        Originally posted by colinod
        Hi

        that seems perfect, i just dont know how to use session variables or how to split them or write to them when you click a button, so basically all of the above!!!!!

        Sorry but my knowledge of asp only goes as far as pulling info from a database
        OK, first things first then. Add to a session variable. This is much easier than pulling data from a db. so if you have a page that is pulling info from a record from a db, a simple form that sends all of the info needed might look like this:
        Code:
        <form action="handler.asp" method="post">
           <input type="hidden" name="recordNum" value="<%=objRS("ID")%>">
           <input type="submit" name="submit" value="Add to cart">
        </form>
        On the form handler, try this:
        Code:
        <%
        if session("recordsInCart") <> "" then
           session("recordsInCart") = session("recordsInCart") + ","
        end if
        
        response.write "Form received<br>"&vbNewLine
        
        for each x in request.form
           response.write x & ": " & request.form(x) & "<br>" & vbNewLine
        next
        
        session("recordsInCart") = session("recordsInCart") + request.form("recordNum")
        response.write "Record added to session variable<br>"&vbNewLine
        
        dim records
        records = split(session("recordsInCart"), ",")
        
        response.write "Currently in the session variable:<br>"&vbNewLine
        for each x in records
           response.write x & "<br>" & vbNewLine
        next
        %>
        Notice you don't need to declare session variables, I just start out by checking to see if it exists, and if so I add a comma, then add the record I want, then I split up the variable on the commas, and print them out. Try it and see if it works, then we'll discuss doing more.

        Jared

        Comment

        • colinod
          Contributor
          • Nov 2007
          • 347

          #5
          not sure what i have done but the server is returning a http 500 error when it goes to the handler page

          Comment

          • jhardman
            Recognized Expert Specialist
            • Jan 2007
            • 3405

            #6
            Originally posted by colinod
            not sure what i have done but the server is returning a http 500 error when it goes to the handler page
            Try to turn off friendly error messages, they always prevent you from seeing the actual error messages. One way to get around it is to replace all the code on the handler with "Hello World" or some such and hit refresh. Then replace the code and refresh again, you should then see the actual error message.

            Jared

            Comment

            • colinod
              Contributor
              • Nov 2007
              • 347

              #7
              Hi I have taken out the first for loop

              Code:
              response.write "Form received<br>"&vbNewLine 
                
              for each x in request.form 
                 response.write x & ": " & request.form(x) & "<br>" & vbNewLine 
              next
              this makes the page appear but it returns the following

              Record added
              currently in variable:
              67676767696969

              this is the right variables and the right amount of each for the clicks i have done, here is the code for the page

              Code:
              <%
              if session("recorsdInCart") <> "" then
              session("recordsInCart") = session("recordsInCart")+","
              end if
              
              session("recordsInCart") = session("recordsInCart") + request.form("recordNum")
              response.write "Record added<br>" &vbNewLine
              
              dim records
              records = split(session("recordsInCart"),",")
              
              response.write "currently in variable:<br>" &vbNewLine
              for each x in records
              response.write x &"<br>" & vbNewLine
              next
              %>

              Comment

              • jhardman
                Recognized Expert Specialist
                • Jan 2007
                • 3405

                #8
                Originally posted by colinod
                this makes the page appear but it returns the following

                Record added
                currently in variable:
                67676767696969
                OK, this doesn't look quite right, there should be more than one line of records added, unless 67676767696969 is one record ID. Try adding the comma to the session variable at a different point, like right after you add the current ID. This will mean the session variable will always have a comma at the end, but you will still be able to use it. Try it and see how it changes.

                Jared

                Comment

                • colinod
                  Contributor
                  • Nov 2007
                  • 347

                  #9
                  Hi

                  I added the comma to the session variable after the current id is added and it returns all the id numbers on seperate lines, i hope thats what it should be doing.

                  Comment

                  • colinod
                    Contributor
                    • Nov 2007
                    • 347

                    #10
                    Hi Just had a further look and its doing as you said i have all variables with commas in between and a comma at the end, i need to fugure out how to use these variables to make a list of the relevant items on the page, im used to just calling out everything at the top of my code??? not sure how to do this

                    What i need to do i stop it from duplicating entries, and then i ant to be able to email the list of variables in a link so someone can email the list to people and they can view it by clicking on the url in an email.

                    Comment

                    • jhardman
                      Recognized Expert Specialist
                      • Jan 2007
                      • 3405

                      #11
                      Originally posted by colinod
                      What i need to do i stop it from duplicating entries,
                      Keeping out duplicates is fairly easy, you just need to search the session variable for the string you are about to add:
                      Code:
                      if instr(session("recordsInCart"), ","&request("recordNum") &",")) < 0 then
                         'add record to session variable
                      else
                         'record has already been added
                      end if
                      Of course this searches for a comma before and after the record number so that if you search for record 1 after 15 has been added it will understand that this is a different record. Does this make sense? Of course you will want to add a special case to the if statement to catch the first record in the list (which won't have a leading comma), something like
                      Code:
                      if instr(session("recordsInCart"), ","&request("recordNum") &",")) < 0 AND instr(session("recordsInCart"), request("recordNum") &",")) <>0 then
                      I'm writing this off the top of my head, so I might have it a little off, you can search w3schools.com for "instr" function to make sure you get it right (or you can test it of course).
                      and then i ant to be able to email the list of variables in a link so someone can email the list to people and they can view it by clicking on the url in an email.
                      Do you know how to send an email from an ASP page? (w3schools might be a big help there as well) Do you know how to generate a URL with querystring data? Do you know how to open querystring data? It's unclear from your phrasing what exactly you are asking.

                      Comment

                      • colinod
                        Contributor
                        • Nov 2007
                        • 347

                        #12
                        Hi

                        I should be able to make an asp page that sends an email, ive done it in the past using cdonts in html it cant be that different in asp.

                        As for generating a URL with querystring data and opening querystring data, have never done that as such, i can send data in a url and gather it on the following page, just not sure how i send a session variable as the computer obviously does not keep this in the url without converting it some how, am i thinking in the right direction

                        Comment

                        • colinod
                          Contributor
                          • Nov 2007
                          • 347

                          #13
                          I have tried the code for checking for duplicates, what i have is now like this

                          Code:
                          <%
                          if session("recorsdInCart") <> "" then
                          session("recordsInCart") = session("recordsInCart")+","
                          end if
                          
                          if instr(session("recordsInCart"), ","&request("recordNum") &",") < 0 then 
                             session("recordsInCart") = session("recordsInCart") + request.form("recordNum")+","
                          response.write "Record added<br>" &vbNewLine
                          
                          end if
                          
                          dim y
                          y = session("recordsInCart")
                          response.write y
                          
                          
                          dim records
                          records = split(session("recordsInCart"),",")
                          
                          response.write "currently in variable:<br>" &vbNewLine
                          for each x in records
                          response.write x &"<br>" & vbNewLine
                          next
                          %>
                          this produces a page that just says

                          currently in variable.

                          does this mean the variables are not being written to the session variable, have i put it in the wrong place??

                          Comment

                          • jhardman
                            Recognized Expert Specialist
                            • Jan 2007
                            • 3405

                            #14
                            Originally posted by colinod
                            does this mean the variables are not being written to the session variable, have i put it in the wrong place??
                            The code looks right to me, but it's been a while since I tried this type of thing. The first "if" statement can be removed, no longer does anything important. In its place, try to response.write the following four data points: the session variable, the request data, the instr() function that's in the next "if" statement, and the same instr() function but with the two arguments switched. See what that gives you.

                            Jared

                            Comment

                            • jhardman
                              Recognized Expert Specialist
                              • Jan 2007
                              • 3405

                              #15
                              Originally posted by colinod
                              Hi

                              I should be able to make an asp page that sends an email, ive done it in the past using cdonts in html it cant be that different in asp.

                              As for generating a URL with querystring data and opening querystring data, have never done that as such, i can send data in a url and gather it on the following page, just not sure how i send a session variable as the computer obviously does not keep this in the url without converting it some how, am i thinking in the right direction
                              Yeah, you are going right, to generate the url, you just need something like this:
                              Code:
                              <a href="myurl.com/shoppingcart.asp?cartContents=<%= urlEncode(session("variableName")) %>">Click here for your shopping cart</a>
                              then the page that opens it needs to do the same thing as any other page that handles the session variable, but it needs to check for the request.queryst ring("variableN ame") instead of the session(":varia bleName").

                              Jared

                              Comment

                              Working...