PDA

View Full Version : Javascript help?


desigal
10-11-2007, 10:19 AM
Hi. I just started learning about Javascript, but I am having trouble on an assignment. Using HTML tags by making a table and heading, was easy, and then I had to put in a javascript code. I put a prompt box which asks the name of whoever's using it, and an alert box stating the person to look at the table with products being sold. I'm not sure how to do the next steps, which are to have two prompt boxes to take as input the name of the product the customer wants and the corresponding price from the table. (The user has to himself do a look up from the table and enter the name and corresponding price, the program doesn’t have to do this) Then, I have to take an input for the quantity of the product required, and then finally based on these inputs I have to calculate the cost of the purchase using the formula:

cost_of_order = price_of_product * quantity_required
Assuming that the shipping cost within the U.S. is $5. The final cost is calculated as cost_of_order + 5
Here is my link:http://www.eden.rutgers.edu/~amreetac/java_assignmentone.html

lansingstudent09101
10-11-2007, 10:19 AM
you need to change the first alert to be
alert("hello" + names + "Please look through the list of products and place your order").

Now you have to decide how you want to take his input. A nice method is to add "onclick" attributes to the table or, have a button at the bottom with a onclick attribute. The advantage of having them on the table is you can put in the prices. If you just put the remaining prompts in the source like you have with these the table won't load until after the script is executed.

Doing this the easy way:
Rule 1: Anything can be a button, all you have to do is put onclick="javascript:functionName();"

one choice is to add a row and cell to the bottom that achieves this
<tr><td colspan="2" onclick="priceCalculate()">Click Here to Calculate Price</td></tr>

then at the top of the program (in javascript tags) put
fucntion priceCalculate()
{
var quantity = prompt("How many Do you want", "");
var price = prompt("How much does it cost","");

}