Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 4257
Latest: Alex998.
New This Month: 1
New This Week: 0
New Today: 0
Stats
Total Posts: 43295
Total Topics: 7523
Most Online Today: 221
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 175
Total: 175

Author Topic: JavaScript, Freight Calculator Help  (Read 3680 times)

0 Members and 1 Guest are viewing this topic.

Offline Empire

  • Member
  • *
  • Posts: 48
    • View Profile
JavaScript, Freight Calculator Help
« on: February 09, 2015, 11:20:26 pm »
I'm just building an basic freight calculator for my site. When the user enters the parcels weight in kilograms in to the text box and clicks on the "Calculate Postage" button, your application will calculate the cost and display the amount in a paragraph.

So calculating the freight are as follows:
If the weight is greater than 0 and less than or equal to 5kg the freight is $7.50
Greater than 5kg and less than or equal 15kg the freight is $12.60
Anything above 15kg is a flat freight charge of $20.00
If the user does not enter a positive number, display an error message

And here is my code so fair,

JavaScript,
Code: [Select]
};

var price = 0;
var shipping = calculateShipping(price);

function calculate() {
var result = 0;
if (price <= 25){
    result = 5kg;
}
else{
    result = price * 10 / 100;
}
var total = result + (price - 0);
window.alert("Shipping is $" + result + ".  Total is $" + total +".");
}

}

HTML
Code: [Select]
<!doctype html>
<html lang="en">

<html>

<head>

<meta charset="utf-8">
<title>Empire's Calculate Shipping</title>
<link rel="stylesheet" href="style.css">
<script src="javascript.js"></script>
</head>

<body><h1>Empire's Calculate Shipping</h1>

<p>Entre Your Postage Weight:
<input type="text" name="text" id="input" />kg
<input type="button" value="Calculate Shipping" onclick="calculateShipping(document.getElementById('price').value);" /></p>
</body>
</html>

 

Related Topics

  Subject / Started by Replies Last post
6 Replies
5465 Views
Last post February 15, 2007, 05:24:44 pm
by SMFHacks
1 Replies
4041 Views
Last post October 12, 2008, 09:15:56 am
by SMFHacks
1 Replies
2696 Views
Last post February 04, 2012, 07:38:38 pm
by SMFHacks
0 Replies
4227 Views
Last post July 18, 2016, 01:36:39 pm
by shuban

+- Recent Topics

Please Help! by SMFHacks
April 17, 2024, 08:04:55 am

Rate own images by fvlog19
April 11, 2024, 10:56:53 am

Tidy Child Boards on 2.1.4 by SMFHacks
April 04, 2024, 03:54:12 pm

Problems SMF 2.0.19 > 2.1.4 SMF Gallery Pro - Recents Images to overall header by Michel68
March 30, 2024, 12:41:08 pm

Can't DROP 'id_member'; check that column/key exists Datei: by SMFHacks
March 30, 2024, 11:58:20 am

No thumbnails on new uploads by Tonyvic
March 29, 2024, 06:26:18 am

Display the Contact Page for guests by SMFHacks
March 27, 2024, 10:55:43 am

is it possible to add support for odysee.com by fvlog19
March 21, 2024, 08:47:51 am

Request for admin notification by davejo
March 10, 2024, 01:31:59 am

I need help with torrent upload by Ineedsmfhelp
March 09, 2024, 10:01:13 pm

Powered by EzPortal