0

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

5
Contributors
6
Replies
31
Views
1 Year
Discussion Span
Last Post by Phaelax
0

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?

0

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.

0

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.

0

@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.

2

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.

Edited by diafol

0

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.

http://codepen.io/anon/pen/NRappo

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.