Hi I'm trying to find a script that will allow me to set multiple options eg. option 1 = 40, option 2 = 15, option 3 = 30 etc
where the user can select any number of the options and it will total the numbers up for them

example there are 10 options, the user only selects 5 of them the calculator will add up the value of just those 5 options and the user can add from the other options or remove from the currently selected options and it will change the added up value of the total

Recommended Answers

All 6 Replies

Sounds like a job for javascript instead of php imo. However.. What seems to be your problem with this? Have you tried it yourself yet?

Something seems missing here. That is, PHP is usually some backend so are you trying to write some app in PHP or did you forget to tell us you have a web server and this is served up on some web page and you want to "find a script"?

Everytime I read "find a script" I worry that was code for "I want someone to write this for me and tell me step by step how to get it working."

I could be wrong.

I didnt ask anyone to write it for me I'm hoping for a pointer in the right direction, I have a script that does multiple aditions at the same time example option 1 requires 3x ingredient A, 5x ingred B, 7xIngredient C and option 2 requires 6x ingredient A, 9x ingred B, 1xIngredient C etc and it tells me the total of all the columns I'm just looking for a simpler version where each option only has 1 variable.

and sry i know i said php, but all my webfiles are php so I prob mixed the script types up.

@wikit. Let's be clear here. There is no such script to be found. What you are asking for is custom and not something you see in a ready to use and install code or system.

You seem to have left a lot unspecified. I can't see any mention of a webfile in your first post. No mention you are going to have this on a server. I know folk want others to divine what's not written but try again, share what you have so far and of course your code and where you think it fails.

Member Avatar

Let's nip this in the bud. PHP is useless for calculator app. Use something like JS. You can be all means use PHP mixed with JS (Ajax), but seeing that JS can handle this sort of thing, it makes no sense to use PHP at all - well for a basic calculator anyway. Unless you're creating a basket / shop type thingy. Where data needs to be pulled from a DB (usually) and the maths is done via PHP since you can't trust anything sent to the server via user input / form / js / url.

PHP can do what you want, as long as you don't mind refreshing the page to calculate the answer. Most would say that's a deal breaker, so use javascript as the others have suggested. You can still use PHP, however, to build the initial form if you have a lot of options or the options are dynamic.
Here's a quick and dirty example. If you have the option, use jquery as it makes the code easier and probably shorter.


Also, your question sounds an awful lot like a homework problem to me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.