view raw
Husky653 Husky653 - 6 months ago 24
HTML Question

How to use date from a form in a script?

I have to make a form where the costumer can enter quantity, orderdate and delivery and then by clicking a button he will get his price.

Now the price depends on the quantity and order date.

He gets a discount of 2.5% if he orders more than 10 items (

q > 10
Now he only gets the discount on the extra items he orders.
If he orders less that 10 then he just pays quantity*341, where 341 is the price of one item.

I managed to do this part and get a result, but then I have to expand the function such that if he orders Monday, Tuesday and Wednesday then he gets a discount of 5%.. I tried to do this but I always get the result
or simply nothing.

Here is what I have so far:

<p>We create a web based interface for calculating the consumers costs. The perception is that it could provide a quick and easy access. The focus of the assignment is the price calculation.</p>
<p1>Quantity</p1> <!-- Note that the costumers only can choose a positive quantity -->
<p1><input type="number" min="1" id="quantity" name="quantity"></p1>
<p1>Order date</p1> <!-- Note that the costumers only can choose a real date -->
<p1><input type="date" id="oDate" name="oDate"></p1>
<p1>Delivery date</p1> <!-- Note that the costumers only can choose a real date -->
<p1><input type="date" id="dDate" name="dDate"></p1>
<button onclick="myCalc()">Calculate Price </button>
<p id="calculate"></p>

function myCalc() {

var q = quantity.value;
var total;
var qDiscount;
var dDiscount;
var oDate = new Date()
var day = oDate.getDay();
var Dday = (day == 1) || (day == 2)|| (day == 3);

if (q > 10) {
qDiscount = (q-10) * 341 * 0.025;
} else {
qDiscount = 0 ;

if (Dday) {
} else {

total = q * 341 - qDiscount - dDiscount

document.getElementById("calculate").innerHTML = total;

Hope someone can help me, I have been stuck with it for hours now.


should be

dDiscount = 0;

Also you missed a semicolon, this:

total = q * 341 - qDiscount - dDiscount

should be this:

total = q * 341 - qDiscount - dDiscount;

(your day checking code looks ok...)