Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

Thread: If..else..if..else for percentage discount, dependent on total

1. If..else..if..else for percentage discount, dependent on total

I have my cumulative totals box at the very end of my order form and I'm required to have another underneath that one that will give a particular discount depending on how great the total of the order is.

Would someone please be able to give me the javascript codes that will allow me to do this and also tell me where I'm to put them.

2. No code, no help.

Show what you have so far.

3. Oh, sorry.

<script language="JavaScript" type="text/javascript">

function CalculateTotal(frm) {
var order_total = 0

for (var i=0; i < frm.elements.length; ++i) {

form_field = frm.elements[i]

form_name = form_field.name

if (form_name.substring(0,3) == "TOT") {

prev = frm.elements[i-1]
prev_name = prev.name

item_price = parseFloat(prev_name.substring(prev_name.lastIndexOf("_") + 1))

item_quantity = parseInt(prev.value)

// Update the order total
if (item_quantity >= 0) {
item_total = item_quantity * item_price
form_field.value = item_total
order_total += item_total

}
}
}

// Display the total rounded to two decimal places
frm.GRANDTOTAL.value = order_total
}

</script>

//and then the last row with the total is:

<tr>
<td></td>
<td></td>
<td></td>
<td>Total</td>
<td><input type="text" name=GRANDTOTAL size="10" onFocus="this.form.elements[0].focus()"></td>

</tr>

//and I need another separate row that'll discount the above total

4. Originally Posted by AnnaKaren
Would someone please be able to give me the javascript codes that will allow me to do this and also tell me where I'm to put them.
//and I need another separate row that'll discount the above total
Sorry, but we will not do your homework for you. It is not really in your best interests that others do all or most of your homework for you. Your teacher may gain a false and exaggerated idea of your programming capabilities and so not offer you the support you need. Also, if you hand in other people's work which you do not completely understand, then you will start to fall behind and your difficulties will increase.

Show your attempt at coding for this, and then doubtless someone will be willing to correct/improve it.

// Display the total rounded to two decimal places
frm.GRANDTOTAL.value = order_total

How does that round to 2 decimal places?

<script language="javascript"> is long deprecated and obsolete. Use <script type = "text/javascript"> instead.

It is your responsibility to die() if necessary….. - PHP Manual

5. I really wanted to see your HTML.

From that JS, I can deduce some of the HTML, but not all of it.

And I'm not convinced that you are approaching the problem in the easiest/best way, in any case.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•