Solved Program to display total value of buttons clicked

September 6, 2012 at 14:13:01
Specs: Macintosh
I need a program/website that has 4 buttons (valued at 2,5,10,20) and a numerical display/field. When I click the button with the value of 2, I need it to display 2 in the numerical display. Then if I click 5, it will add 5 to the existing 2 in the display, therefore it will now display 7. Also, this has to be able to be accesed by multiple computers on a local network, meaning all computers access the same display total, so if computer A presses the 2 button, computer B's display total will show 2, then if computer B presses the 5 button, both totals will now show 7. Hopefully this isn't too confusing. Thanks

See More: Program to display total value of buttons clicked

Report •


✔ Best Answer
September 7, 2012 at 08:13:22
maxwellpoole: I guess PHP would be easiest, as that comes preinstalled on Macs. For sharing the counter, you can go with a memory cache if you don't need the value to persist. If you do, you can go with a database, like mysql.

mikelinus: Everyone's using multiple functions. I'm not sure why.

<html><head><title>Counter</title>
  <script type="text/javascript">
    var counter = 0;
    function increase(inc) {
      document.getElementById('counter').value = counter += inc;
    }
  </script>
</head><body>
  <a href="#" onclick="increase(2);">2</a><br /><br />
  <a href="#" onclick="increase(5);">5</a><br /><br />
  <a href="#" onclick="increase(10);">10</a><br /><br />
  <a href="#" onclick="increase(20);">20</a><br /><br />
  <input id="counter" value="0" />
</body></html>

How To Ask Questions The Smart Way



#1
September 7, 2012 at 02:10:29
I dont know if a program like that exists, but you can develop somethings like this very easily. Seeing as its not an extremely complicated applicated id probably do it using VB.net or even easier VB6.

You can either store the value in a flat file such as notepad, or a spreadsheet or even a database and have your application either detect a change in the file or read from the file at specified intervals.

You could also use something like Winsock and send the value to each other instance of the application but that may become slightly complicated.

I notice your specs say 'machintosh' if that is the case then i wont know how to help you as i have no experience with machintosh machines.


Report •

#2
September 7, 2012 at 04:29:44
First of all thanks for your reply! But yes, I am trying to do this on a Mac. That's what made me wonder if it would be possible to write this application/program in a HTML format? That way it could be able to be run in a browser? Do you know where I could get information on how to do this? Sorry, I'm very new at learning programming.

Thanks!


Report •

#3
September 7, 2012 at 05:17:15
I've been playing around and came up with this code:

<html><head>
<script><!--
var Two = 0 ;
function AddTwo(){
Two = Two + 2;
document.getElementById('Total').innerHTML = Two + Five + Ten + Twenty ;
}
var Five = 0 ;
function AddFive(){
Five = Five + 5;
document.getElementById('Total').innerHTML = Two + Five + Ten + Twenty ;
}
var Ten = 0 ;
function AddTen(){
Ten = Ten + 10;
document.getElementById('Total').innerHTML = Two + Five + Ten + Twenty ;
}
var Twenty = 0 ;
function AddTwenty(){
Twenty = Twenty + 20;
document.getElementById('Total').innerHTML = Two + Five + Ten + Twenty ;
}
// --></script>
</head>
<body style="left:-111px; top:-44px; " >
<span id="Total" >$0</span>

<button style="background-color:#008000; " onclick="AddTwo()" >$2.00</button>
<button style="background-color:#0000FF; " onclick="AddFive()" >$5.00</button>
<button style="background-color:#FF0000; " onclick="AddTen()" >$10.00</button>
<button style="background-color:#FFFF00; " onclick="AddTwenty()" >$20.00</button>


</body></html>

This program has 4 buttons valued at 2,5,10,20 and a display that has the total. For example, when you press the 2 button the total will display 2. Then if I press 5, the display will show 7, and so on.

However, would it be possible to access a simple text file on the same website/server and use that as the total, for example if I press the 2 button, the external text file will now have a number 2, then if I press 5, the external text file will now display a 7, and so on.

If so could someone help me with this?

Thanks


Report •

Related Solutions

#4
September 7, 2012 at 05:32:14
You would need a web host with server-side scripting, and some way of saving data across all sessions. It's not difficult, but it is dependent on your web host environment.

How To Ask Questions The Smart Way


Report •

#5
September 7, 2012 at 06:21:52
I'm going to be running this on a local network, using Apache probably.

Report •

#6
September 7, 2012 at 07:13:59
Good, so you get to pick the language and the database. Which languages do you know?

How To Ask Questions The Smart Way


Report •

#7
September 7, 2012 at 07:16:17
I'm not very experienced in any, but I have a little knowledge of HTML and Javascript.

Report •

#8
September 7, 2012 at 07:31:21
here is an html version i worked up
<html>
<head>
<title>Counter</title>
<script type="text/javascript">
var counter = 0;

function increase() {
counter += 2;
document.getElementById('counter').value = counter;
}
function increase5() {
counter += 5;
document.getElementById('counter').value = counter;
}
function increase10() {
counter += 10;
document.getElementById('counter').value = counter;
}
function increase20() {
counter += 20;
document.getElementById('counter').value = counter;
}

</script>
</head>
<body>
<a href="#" onclick="javascript:increase();">2</a><br /><br />
<a href="#" onclick="javascript:increase5();">5</a><br /><br />
<a href="#" onclick="javascript:increase10();">10</a><br /><br />
<a href="#" onclick="javascript:increase20();">20</a><br /><br />
<input id="counter" value="0" />

</body>
</html>

mike

edit: you know what happens when you read half a question...you only do half an answer...my bad

edit2: Thanks Razor2.3


Report •

#9
September 7, 2012 at 07:39:06
Thanks Mike! Is it possible to use that as so different computers can change/access the same counter?

Report •

#10
September 7, 2012 at 08:13:22
✔ Best Answer
maxwellpoole: I guess PHP would be easiest, as that comes preinstalled on Macs. For sharing the counter, you can go with a memory cache if you don't need the value to persist. If you do, you can go with a database, like mysql.

mikelinus: Everyone's using multiple functions. I'm not sure why.

<html><head><title>Counter</title>
  <script type="text/javascript">
    var counter = 0;
    function increase(inc) {
      document.getElementById('counter').value = counter += inc;
    }
  </script>
</head><body>
  <a href="#" onclick="increase(2);">2</a><br /><br />
  <a href="#" onclick="increase(5);">5</a><br /><br />
  <a href="#" onclick="increase(10);">10</a><br /><br />
  <a href="#" onclick="increase(20);">20</a><br /><br />
  <input id="counter" value="0" />
</body></html>

How To Ask Questions The Smart Way


Report •

#11
September 7, 2012 at 10:28:14
You're better off using a small PostgreSQL or MySQL database to store values for both security and manageability reasons. Like Razor said, PHP would be the easiest running either Apache or nginx.

If you want to stick with a language you know, check out node.js which is a server-side JavaScript framework.

Tony


Report •

#12
September 7, 2012 at 10:33:14
Alright I'm currently working on building it like a form with radio buttons that uses PHP, and submits to an SQL database. However, I'm not really sure exactly how to get it all working yet. Watching lots of youtube videos.

Report •

#13
September 7, 2012 at 10:57:57
I'm not making any progress with this PHP, SQL stuff. I've figured out how to run a local server with MAMP and build table's and stuff on Php myadmin. As well, I've got my database running through a MySQL connection in Dreamweaver but I just can't for the life of me figure out to submit a form from a page that sends data to the SQL database and then take that data and be able to add it together. Can someone help with that?

Thanks


Report •

#14
September 7, 2012 at 12:39:43
This is a pretty good site for all things web.

Tony


Report •

Ask Question