Hi. I'm looking for a script (in either JavaScript, PHP or both) where you enter the amount of servings you want for a recipe, and it'll calculate the recipe. I can't find a script anywhere!
Can anyone help me?

To see an example, go to http://tastykitchen.com/recipes/breads/plain-bagels/

Thanks!

Recommended Answers

All 6 Replies

You have just answered your own question. The link you have provided appears to use JavaScript to do exactly what you ask. Why not view the source and extract the code?

Otherwise, find the ingredient measurements for a single serving and multiply this value by however many people the recipe should serve. It's simple multiplication.

Because it looks like the site also uses PHP for the conversion. I downloaded the code, but it looks like PHP creates a different script for each recipe. As for the simple multiplication, I need to be able to convert recipe units as well (cups, tablespoons, etc) Do you know of a way to convert it?
Thanks

interview the one who makes this kind of food.:) then you can formulate your own formula. it is like a simple math then. :) use if statements or loops or if there is a patter then use and equation.

if there is no equation. if input == 1 then 1tblespoon; else if input == 2 then 3tblespoon. piece of cake right?

commented: nice pun :) +13

If you spent even a fraction of a minute looking at their HTML you'd notice an ajax link like this:
http://tastykitchen.com/recipes/wp-content/plugins/wp-recipes/ajax.php

If you use Firefox, Chrome or Safari, and opened the developer tools/firebug, and adjusted the servings you'd see that the site is using that to make an ajax request. Which then returns a full block of html that is replaced on the site.

Although that is not useful, what you will notice is the /plugins/wp-recipe/ part of that url.
Simply googled for "wp-recipe plugin" and got http://wordpress.org/extend/plugins/wp-recipes/

SImply download the plugin and review the actual PHP source code and you should have a great place to start from.

I did notice the ajax.php.

Thanks for the tip!

I actually created my own calculator script. Thanks for all the suggestions!

Be a part of the DaniWeb community

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