Page 1 of 1

basic web calculator

Posted: Thu Oct 13, 2016 10:01 pm
by joejoe
Hi,

I would like to create a basic web calculator using nL.

I would like to display three images which correspond to three different values (say 1, 2 and 3).

I would like to display a running total as the images are clicked on.

So, I would start with the value of 0.

I click on the first image (which has a value of 1), and the total updates to 1.
Then I click on the second image (which has a value of 2), and the total updates to 3.
Then I click on the third image (which has a value of 3), and the total updates to 6.
Then I click on the second image again, and the total updates to 8.
Etc..

And then I have a buton to clear.

Would anyone have pointers to get me going in the right place?

Specifically:

Do I need to use a web form to do this?
Do I need to use cookies or can I do this without cookies?

Thanks very much for any help to get me going in the right direction! :0)

Re: basic web calculator

Posted: Fri Oct 14, 2016 8:23 pm
by TedWalther
Maybe this will help you. Don't think you need nL at all. Here is some code that does something very similar, and should answer your questions:

http://reactor-core.org/baccarat.html

If you want to use nL to store the clicks in a database or something, then use AJAX

http://www.newlisp.org/index.cgi?page=AJAX_and_newLISP

The baccarat HTML page was generated by newLisp; I found it easier than typing all the html tags by hand. More accurate too.

Re: basic web calculator

Posted: Fri Oct 14, 2016 8:45 pm
by joejoe
Hi Ted,

Thanks for the links and tips!

I am planning to have it be a lot more involved in the future, so I want to use nL because I know I can do everything with it.

I would rather not have to set up a database, but will if I must.

I was thinking to keep my tally in the url bar in a format something like this:

index.cgi?add=2&total=14

How is your baccarat game keeping tally? Is this with a db?

Thanks for your help Ted!