(urgent!) simple JavaScript
Hello all,
I am making a price calculator using javascript. I've been struggling hours trying to figure this out, yeah i'm really new to this. Here is the requirements:
The calculator would calculate the price of the items the user selects.
List a number of products to sell
Include the ability to choose quantity
Include other options (such as the size, color, etc of the item)
Button to calculate price (most calculate the price, not store and display)
Button to clear the calculated value
That's all, thank you so much for your help!!
Hi,We are ready to help you reach us..
give us some code? or do you want to code it for you?
When the only tool you have is a hammer, everything looks like a nail.
code
hello, I was hoping if it's possible that you can write the code out for me. greatly appreciated.
Hi,
I hope this code may help you to get the solution you want
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Calc</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function() {
$('#calculateTotal').click(function() {
var shirtsPrice = 10.50, perColorPrice = 5.99;
var inputNum_of_Shirts = $('#shirts').val();
var inputNum_of_FColor = $('#colorsOnFront').val();
var inputNum_of_BColor = $('#colorsOnBack').val();
var totalCost = (inputNum_of_Shirts*parseFloat(shirtsPrice))
+(parseFloat(perColorPrice)*inputNum_of_FColor)
+(parseFloat(perColorPrice)* inputNum_of_BColor );
var perShirtCost = (parseFloat(shirtsPrice))
+(parseFloat(perColorPrice)*inputNum_of_FColor)
+(parseFloat(perColorPrice)*inputNum_of_BColor);
$('#total').html(formatCurrency(totalCost));
$('#perShirt').html(formatCurrency(perShirtCost));
$('#result').css('display', 'block');
});
});
// This Function I have searched from Web
function formatCurrency(strValue)
{
strValue = strValue.toString().replace(/\$|\,/g,'');
dblValue = parseFloat(strValue);
blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
dblValue = Math.floor(dblValue*100+0.50000000001);
intCents = dblValue%100;
strCents = intCents.toString();
dblValue = Math.floor(dblValue/100).toString();
if(intCents<10)
strCents = "0" + strCents;
for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
dblValue.substring(dblValue.length-(4*i+3));
return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
}
-->
</script>
</head>
<body>
<form id="calc" name="calc">
<p>
<input id="shirts" name="shirts" type="text">
<label for="shirts">Number of Shirts</label>
</p>
<p>
<input id="colorsOnFront" name="colorsOnFront" type="text">
<label for="colorsOnFront">Number of Colors on Front</label>
</p>
<p>
<input id="colorsOnBack" name="colorsOnBack" type="text">
<label for="colorsOnBack">Number of Colors on Back</label>
</p>
<p><input name="calculateTotal" id="calculateTotal" type="button" value="Calculate Total" /></p>
<div id="result" style="display:none;"><strong>Total:</strong> <span id="total"></span> <strong>Per Shirt:</strong> <span id="perShirt"></span></div>
</div>
</form>
</body>
</html>
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks