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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Submit Button Counter / Chart

    New here to CodingForums thanks for having me. Hello All!

    I read an article on this forum that was about a counter that tracked button clicks. The problem is it's not quite what I was looking for so I'm posting to see if anyone can help on this matter.

    What we have is a very simple site that has a drop down box that links to several different forms that are filled out then submitted (to a server that accepts HTTP POSTs). What I'm looking to do is put a small chart on the main page with the drop down that shows how many times a specific form was submitted, in essence tracking the submit button clicks on those forms. To be exact we have six forms. Please correct me if im wrong and there is a better way to accomplish this but that was the only way I could think of. I do not have .asp or .php capabilities on the paticular site so sticking to a javascript would be best.

    If you need additional info let me know. Thanks for any help anyone can provide me with.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    Don't see any way to do this without *some* server-side capabilities.

    You can't save site-global data anywhere except on the server. And JavaScript can't save data anywhere, in the general case, except in cookies. And each user has his/her own set of cookies. So you could show "Joe" that he has downloaded 3 files, but there would be no way for "Mae" to know about Joe's download.

    ASP, PHP, JSP, CGI, CF, whatever. You need *SOME* server side technology to make this work. Irrelevant to JavaScript.

    NOTE: *IF* you have server side capabilities on some *other* server, you could use AJAX to have JS code from HTML pages on this server both get the table and update it on the server-capable server.

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If I could manage *some* server side capabilitities what would you suggest?
    Thanks BTW for the response.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    Really doesn't matter. Any of the common technologies are more than adequate for this.

    You should probably use a simple database, unless you are talking about only a handful of people (in which case you could get away with storing the data in a text file).

    You aren't talking about more than a couple of dozen lines of code, in JSP/PHP/ASP, along with a simple database (say Access or MySQL or even a ".csv" file).

  • #5
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Correct very small. A txt file would be sufficient. This site is just a portal for submitting those forms I spoke of. I would probably log the values of the counter at the end of each month and start over.

    Could you help me with a generalization of how to do it say using .asp to get me started? Once I figure out how to get started I "think" I can get going on it. I just really don't have a clue where to start. Or a basic concept of how to get the onclick to log into a txt file then to display it somewhere on the main page.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    If using ASP, it's about as easy to use an Access DB as it is to use a file, but okay...

    We will say that the file format is this:
    [code]
    name : count
    [/count}
    with each person on a separate line.

    So the file might look like:
    Code:
    Mark:3
    Joe:1
    Mary:5
    John:11
    And anybody who has not submitted a form doesn't even appear in the file.

    We will put the file into a directory named "data" that is under the root directory. We'll put the code in the root directory. We will assume that you will invoke the page by hitting a URL of the form http://www.yoursite.com/countDownloads.asp?name=John+Doe

    Okay?
    Code:
    <%
    name = Request("name")
    Set FSO = Server.CreateObject("Scripting.FileSystemObject")
    Set infile = FSO.OpenTextFile( Server.MapPath("data/downloads.txt") )
    lines = infile.ReadAll ' reads entire text file into memory
    infile.Close
    
    lines = Split( lines, vbNewLine ) ' break text into an array of lines
    done = False
    For i = 0 To UBound(lines)
        temp = Split( lines(i), ":" )
        If LCase(name) = LCase(temp(0)) Then
            ' aha!  this person already in the file...change his/her count:
            temp(1) = CINT( temp(1) ) + 1
            ' put the line back in place:
            lines(i) = Join( temp, ":" )
            done = True
            Exit For ' and we are done
        End If
    Next
    If Not done Then
        ' that name not found in the file, so add a line:
        ReDim Preserve lines( UBound(lines) + 1 ) ' bump size by 1
        lines( UBound(lines) ) = name & ":1" ' give this person one download
    End If
    ' true says overwrite existing file:
    Set outfile = FSO.CreateTextFile( Server.MapPath("data/downloads.txt"), True )
    outfile.Write Join( lines, vbNewLine ) ' write out all the lines
    outfile.WriteLine "" ' with a terminating line break
    outfile.Close
    %>
    Yeah, would actually be slightly shorter to use a database.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    Just for grins, here it is using an Access DB, also in the "data" directory:

    Code:
    <%
    name = Trim(Request("name"))
    If name = "" Then Response.End ' no name?  do nothing
    name = Replace( name, "'", "''" )
    
    Set conn = Server.CreateObject("ADODB.Connection")
    Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
            & "Data Source=" & Server.MapPath("./data/downloads.mdb")
    
    SQL = "UPDATE userDownloads SET count=count + 1 WHERE name='" & name & "'"
    howmany = -1
    conn.Execute SQL, howmany
    If howmany <= 0 Then
        SQL = "INSERT INTO userDownloads (name,count) VALUES('" & name & "',1)"
        conn.Execute SQL
    End IF
    conn.Close
    %>

  • #8
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Im going to sit down this weekend and play around with that. Thanks!


  •  

    Posting Permissions

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