11 Replies - 763 Views - Last Post: 20 April 2012 - 09:27 AM

#1 tdrunner95  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 21-April 11

[Task] Click a button, keeps tracks of clicks.

Posted 28 March 2012 - 05:07 AM

I have a button on a website that I'm building. However when someone clicks the button, I want the website to display how many times it has been clicked. Is there anyway I can do this? Thanks.
Is This A Good Question/Topic? 0
  • +

Replies To: [Task] Click a button, keeps tracks of clicks.

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2936
  • View blog
  • Posts: 7,690
  • Joined: 08-June 10

Re: [Task] Click a button, keeps tracks of clicks.

Posted 28 March 2012 - 05:20 AM

the technique you’re searching for is called "Closure". alternatively you can set a counter (e.g. an input field) and increment its value repeatedly.

This post has been edited by Dormilich: 28 March 2012 - 05:22 AM

Was This Post Helpful? 0
  • +
  • -

#3 Cbeppe  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 215
  • Joined: 16-September 09

Re: [Task] Click a button, keeps tracks of clicks.

Posted 30 March 2012 - 04:40 PM

Is it just me, or is this very easily done in Javascript? If you want the same count to be displayed to all visitors, you would need a server-side script as well as a DB though...
Was This Post Helpful? 0
  • +
  • -

#4 tdrunner95  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 21-April 11

Re: [Task] Click a button, keeps tracks of clicks.

Posted 02 April 2012 - 06:18 AM

View PostCbeppe, on 30 March 2012 - 04:40 PM, said:

Is it just me, or is this very easily done in Javascript? If you want the same count to be displayed to all visitors, you would need a server-side script as well as a DB though...

Ugh, great. I don't think my class will let me create a database.
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2936
  • View blog
  • Posts: 7,690
  • Joined: 08-June 10

Re: [Task] Click a button, keeps tracks of clicks.

Posted 02 April 2012 - 06:29 AM

you only need a database if you need to save the clicks across all users.
Was This Post Helpful? 0
  • +
  • -

#6 Creecher  Icon User is offline

  • I don't care
  • member icon

Reputation: 556
  • View blog
  • Posts: 2,044
  • Joined: 06-March 10

Re: [Task] Click a button, keeps tracks of clicks.

Posted 02 April 2012 - 07:25 AM

Well he could save it to a text file, but that could be abused (depending on the method he uses to count the clicks).
Was This Post Helpful? 0
  • +
  • -

#7 tdrunner95  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 21-April 11

Re: [Task] Click a button, keeps tracks of clicks.

Posted 20 April 2012 - 07:49 AM

View PostDormilich, on 02 April 2012 - 06:29 AM, said:

you only need a database if you need to save the clicks across all users.

Now how would I go about doing that?
Was This Post Helpful? 0
  • +
  • -

#8 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2936
  • View blog
  • Posts: 7,690
  • Joined: 08-June 10

Re: [Task] Click a button, keeps tracks of clicks.

Posted 20 April 2012 - 07:56 AM

make a table with a numeric field. and every time you click the button, make an AJAX request to increase the number by one. (yea and of course you have to fetch the counter value from the DB as well).
Was This Post Helpful? 0
  • +
  • -

#9 enjoibp3  Icon User is offline

  • New D.I.C Head

Reputation: 14
  • View blog
  • Posts: 47
  • Joined: 02-March 11

Re: [Task] Click a button, keeps tracks of clicks.

Posted 20 April 2012 - 07:59 AM

Look in to flat file database if you can't get access to an actual database. :turned:
Was This Post Helpful? 0
  • +
  • -

#10 tdrunner95  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 21-April 11

Re: [Task] Click a button, keeps tracks of clicks.

Posted 20 April 2012 - 08:03 AM

View PostDormilich, on 20 April 2012 - 07:56 AM, said:

make a table with a numeric field. and every time you click the button, make an AJAX request to increase the number by one. (yea and of course you have to fetch the counter value from the DB as well).

Ouch, that sounds a little hard. I have a database and everything. I am just a complete n00b at it. I'll see if my teacher can try and help me.

You guys can see the site that I'm trying to do this on here.
Was This Post Helpful? 0
  • +
  • -

#11 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2936
  • View blog
  • Posts: 7,690
  • Joined: 08-June 10

Re: [Task] Click a button, keeps tracks of clicks.

Posted 20 April 2012 - 09:14 AM

and that only requires a very simple database where you don’t have any real need for DB Normalisation …
Was This Post Helpful? 0
  • +
  • -

#12 tdrunner95  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 21-April 11

Re: [Task] Click a button, keeps tracks of clicks.

Posted 20 April 2012 - 09:27 AM

View PostDormilich, on 20 April 2012 - 09:14 AM, said:

and that only requires a very simple database where you don’t have any real need for DB Normalisation …

I will look into this. Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1