Welcome to Dream.In.Code
Getting Help is Easy!

Join 119,782 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,402 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Javascript Calculations

 
Reply to this topicStart new topic

Javascript Calculations

banditt07
post 29 Jun, 2008 - 02:39 PM
Post #1


New D.I.C Head

*
Joined: 28 Apr, 2008
Posts: 4

Im trying to create a Javascript program that calculates a customer’s order from your company based on the quantity of the item and the price entered by the customer and total the complete order. Display the results in an alert dialog box. Provide validation also. Here is my code:

<!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 content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Antonio Palmer Unit 6</title>
<style type="text/javascript">
.style1 {
border-style: solid;
border-width: 2px;
}
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false;}
else {return true}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(email,"Email must be filled out!")==false)
{email.focus();return false;}
}
}
</style>
<style type="text/css">
.style1 {
border-style: solid;
border-width: 2px;
}

function CalculateSum(Atext, Btext, form)
{
var A = parseFloat(Atext);
var B = parseFloat(Btext);
form.Answer.value = A*75.00 + B*30.00;
}

// end of JavaScript functions -->
</SCRIPT>

</style>
</head>

<body>

<h1>Palmer's Web Design Company Order Form</h1>
<p>&nbsp;</p>
<p>Please Place Your Order Here</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Item&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Qty&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Price&nbsp;</p>


<table class="style1" style="width: 100%">
<tr>
<td class="style1" style="height: 56px; width: 574px">&nbsp;Web Pages&nbsp;(Per
Page)</td>
<td class="style1" style="height: 56px; width: 114px">
<form method="post">
<input name="Atext" style="width: 74px; height: 40px" type="text" /></form>
</td>
<td class="style1" style="height: 56px">
<form method="post">
<input name="priceText1" style="width: 83px; height: 34px" type="text" value="75.00" /></form>
</td>
</tr>
<tr>
<td class="style1" style="height: 66px; width: 574px">Web Hosting
(Number of Years)</td>
<td class="style1" style="height: 66px; width: 114px">
<form method="post">
<input name="Btext" style="width: 75px; height: 46px" type="text" /></form>
</td>
<td class="style1" style="height: 66px">
<form method="post">
<input name="priceText2" style="width: 80px; height: 46px" type="text" value="30.00" /></form>
</td>
</tr>
<tr>
<td style="height: 78px; width: 574px">&nbsp;&nbsp;
<form method="post">
<input name="Button1" style="width: 102px; height: 21px" type="button" value="Calculate Total" />&nbsp;&nbsp;
</form>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
<td class="style1" style="height: 78px; width: 114px"></td>
<td class="style1" style="height: 78px">
<form method="post">
<input name="form" style="width: 81px; height: 49px" type="text" /></form>
</td>
</tr>
</table>
<p>&nbsp;</p>

<p><input name="ClearButton" style="width: 100px" type="button" value="Clear Field" /></p>
<form method="post">
<form name="calculator" method="post">
<p><input type="button" value="calculate total" name="calculatebutton" onclick="calculatesum(this.form.input_a.value, this.form.input_b.value, this.form)"></p>
<p><input type="button" value="clear fields" name="clearbutton" onclick="clearform(this.form)"></p>
<p>total = <input type=text name="total" size=12></p>
</form>

</body>

</html>


User is offlineProfile CardPM

Go to the top of the page


Winstinology
post 30 Jun, 2008 - 12:16 PM
Post #2


D.I.C Head

Group Icon
Joined: 8 May, 2008
Posts: 218



Thanked 2 times

Dream Kudos: 75
My Contributions


You'll want to use script instead of style... like so:


CODE

<script type="text/javascript">

function yourFunction()
{
    // Code here..
}

</script>

User is offlineProfile CardPM

Go to the top of the page

ch__
post 30 Jun, 2008 - 12:59 PM
Post #3


New D.I.C Head

*
Joined: 7 Nov, 2007
Posts: 21


My Contributions


Looks like you should try reading a book first.
User is offlineProfile CardPM

Go to the top of the page

chili5
post 5 Jul, 2008 - 05:15 AM
Post #4


D.I.C Addict

****
Joined: 28 Dec, 2007
Posts: 525



Thanked 4 times
My Contributions


I would get a book on JavaScript, which will explain how to do this. Although you should use code tags for code to prevent the page from scrolling like it did here.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/15/08 09:42PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month