By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,757 Members | 1,990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,757 IT Pros & Developers. It's quick & easy.

Estimate script for products

P: 6
Hi there, This will be my first post, and probably one of many to come.

I'm new here, and i hope you guys can help me.
I'm building a site in dreamweaver for a customer, and unfortunately have very little knowledge of scripting. (if anyone knows where i can get tutorials I would appreciate it)

Here's what i need to do.

He wants a list of products with prices, and then a radio button next to each product which selects it and then adds the total at the bottom of the page.

I hope this is clear enough. any help will be appreciated, and i hope that this is in the right thread.

Regards

SpydrSS
Jun 1 '07 #1
Share this Question
Share on Google+
4 Replies


P: 93
If you want tutorial type stuff I would recommend getting a book on PHP, or borrow one from your library (I read one by Larry Ullman when I started, which was really good, but I don't know which parts of the world it's published in (I'm in UK)).

I'm guessing you're going to be storing your data in a database? There are lots of books on using php with mysql, so you can kill two birds with one stone there!

In terms of adding up the price, I think javascript is going to be your friend there. If you put some javascript in your page that adds up the price and displays the total each time something is clicked, then it saves you having to re-load the page every time someone clicks one of the radio buttons. If you use javascript to add up and display the prices though, make sure that your php script calculates the price itself as well when the page is submitted. Otherwise someone could fiddle the javascript and make the total add up to less than it should be and screw you over!

Oh, another small point... if you want the user to be able to select several items in the list you need to use check boxes not radio buttons.
Jun 1 '07 #2

cyberking
P: 84
Hi there, This will be my first post, and probably one of many to come.

I'm new here, and i hope you guys can help me.
I'm building a site in dreamweaver for a customer, and unfortunately have very little knowledge of scripting. (if anyone knows where i can get tutorials I would appreciate it)

Here's what i need to do.

He wants a list of products with prices, and then a radio button next to each product which selects it and then adds the total at the bottom of the page.

I hope this is clear enough. any help will be appreciated, and i hope that this is in the right thread.

Regards

SpydrSS
Hi,
Thats not at all a problem and yes "You are in the perfect forum!"
Well, as you know / if you dont know too, each radio button has a VALUE parameter associated with it. or hang on, let me take an example and explain it. The following example has two products priced $1 and $2 and on submit button being clicked, shall add them, to give you $3 as the answer.

//Please note the value field, it is the price of the product

Expand|Select|Wrap|Line Numbers
  1. <form method="post" action="add.php">
  2. <input type="radio1" name="product1" value="1" />Product 1 [costs $1]
  3. <input type="radio2" name="product2" value="2" />Product 1 [costs $2]
  4. <input type="submit" value="Checkout">
  5. </form>
[Please use CODE tags when posting source code. Thanks! --pbmods]

//Now here, we finally have a button labelled checkout, Also, to be noted that if the first radio is clicked, then the parameters associated with it are : Name : Radio1, Value = 1 or $1. Please note: We use name parameter to access that radio.

on the submit button being clicked, we have add.php to do the processing job for us.


add.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if( (isset(radio1) ) 
  3.  {
  4. $price1=$_POST['radio1'];
  5.  }
  6. else
  7. {
  8. $price1 = 0;
  9. }
  10.  
  11. if( (isset(radio2))
  12.  {
  13. $price2=$_POST['radio2'];
  14.  }
  15. else
  16. {
  17. $price2 = 0;
  18. }
  19.  
  20. $result _or_sum = $price1 + $price2;
  21. }
  22. echo $result_or_sum;
  23. ?>
There you go, What we are doing here is we initially check if both the radio buttons have been selected. If both are selected then we assign the values of radio1 and radio2 to variables $price1 and $price2 respectively else if only one is set or if the user has selected only one of the radio buttons, then we set the unselected radio's corresponding variable to 0. And fnally we add the variables. And store the sum in the $result_or_sum variable.

Guess you understand this. You can extend the same concept to a 1000 products if you wish! Good luck

Regards
CyberKing (Soon to be MD of BytesandBytes :-) )
Jun 1 '07 #3

cyberking
P: 84
Hi again,
Ah how foolish! I never thought bout it!
As adamalton says, use checkboxes and radio s wont do the job for you, DUH!!
```Dumb me````

Also, the above script wont change, just replace the type = "radio" to type = "checkbox" and it shall work


Regards again
Jun 1 '07 #4

P: 6
Thanks, You guys are great...

My bad on the radio buttons, but anyway, I understand the concept a little, but I am a total newbie at this... Let me try get this right, If i go to Dreamweaver CS3, Design my page, Can I just install the php script above, and obviously edit the coding...

Sorry, As I Said I need help...

Regards

Stanley
Jun 3 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.