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
4 3129
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.
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 - <form method="post" action="add.php">
-
<input type="radio1" name="product1" value="1" />Product 1 [costs $1]
-
<input type="radio2" name="product2" value="2" />Product 1 [costs $2]
-
<input type="submit" value="Checkout">
-
</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 -
<?php
-
if( (isset(radio1) )
-
{
-
$price1=$_POST['radio1'];
-
}
-
else
-
{
-
$price1 = 0;
-
}
-
-
if( (isset(radio2))
-
{
-
$price2=$_POST['radio2'];
-
}
-
else
-
{
-
$price2 = 0;
-
}
-
-
$result _or_sum = $price1 + $price2;
-
}
-
echo $result_or_sum;
-
?>
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 :-) )
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
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
Sign in to post your reply or Sign up for a free account.
Similar topics
by: James Morrow |
last post by:
i need a script for reviewing products (much like epinions.com)
written in either perl or php (can't use asp). i am very strapped for
time and need a functional script asap, which is why i dont...
|
by: Sims |
last post by:
Hi,
I recall a function that would tell me how long it took to generate an
output.
But for the life of me I cannot remember it.
Dow anybody know it? Or do I have to write something myself,...
|
by: Jo_Calico |
last post by:
I love the Dynamic Drive cross browser marquee script. I'd like to
make the text loop immediately after completion, so the beginning runs
right after the end (does that make sense?). Could anyone...
|
by: Rich |
last post by:
I have a project that I would Greatly Appreciate some direction.
My goal is to create a "Sales Assistant Script" that recommends products
based upon Response's to questions.
I know enough...
|
by: JA |
last post by:
Hi,
I have this JavaScript that is supposed to show random products from my
database, and show something different every time you refresh or revisit.
But I keep getting an error - on my computer...
|
by: Bob |
last post by:
I have recently joined a healthcare company where I am the solo
programmer. I am going to be starting work on a project. The
management has asked me to provide an estimate of hours I am going to...
|
by: imtmub |
last post by:
I have a page, Head tag Contains many Scripts and style sheet for Menu and Page. This code working fine and displaying menus and page as i wanted.
Check this page for reference....
|
by: happyse27 |
last post by:
Hi All,
I modified the user registration script, but not sure how to make it check for each variable in terms of preventing junk registration and invalid characters?
Two codes below :
a)...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Many websites have a form or a link you can use to download a file. You click a form button or click...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |