HTML Tutorial


 /help/HTML Help Forum   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Calculating total value
Post new topic   Reply to topic    HTML Help Forum -> Javascript
View previous topic :: View next topic  
Author Message
iamhaziq



Joined: 24 Jan 2009
Posts: 3

PostPosted: Sat Jan 24, 2009 9:22 pm     Calculating total value Reply with quote

Hello,

I'm new with website building, and I'm pretty hopeless with Javascript..
I'm constructing an email submitting form. The form turned out alright, but I failed to calculate the totals.
Can someone help me out? I appreciate it.

The script:

Code:

<!--
function orderTotal(oform, prefix)
{
// set references to fields
var qty = oform[prefix + "_qty"];
var stHold = oform[prefix + "_stHold"];
var price = oform[prefix + "_price"];
var stVis = oform[prefix + "_stVis"];

// only bother if the field has contents
if (qty == "")return;

// if the with is not a number (NaN)
// or is zero or less
// everything goes blank
if(isNaN(qty.value) || (qty.value <= 0))
   {
   qty.value = "";
   stHold.value = "";
   }
   
// else the field is a valid number, so calculate the
// total order cost and put that value in the
// hidden subtotal field
else
   stHold.value = (Math.round(qty.value * price.value * 100))/100;

// call the routine which checks if the
// visible subtotal is correct
visTotal(oform, prefix);
}

// checks if the visible subtotal is correct
// ie, if it equals the hidden subtotal field
function visTotal(oform, prefix)
{
var stHold = oform[prefix + "_stHold"];
var stVis = oform[prefix + "_stVis"];

if (stVis.value != stHold.value)
   stVis.value = stHold.value;
}
function calcTotal(oform, prefix)
{
var stHold = oform[prefix + "_stHold"];
var stVis = oform[prefix + "_stVis"];
if (stVis.value != stHold.value)
   stVis.value = stHold.value
}
// -->


The Basic html:
Code:

<html>
<body>
<table border="1" cellpadding="3">
<!-- table titles -->
<tr style="tableheader">
   <th>Item</th>
   <th>Quantity</th>
   <th>Price</th>
   <th>Total</th>
   </tr>

<!-- Tayammum Kit -->
<tr>
   <td>Innolux Tayammum Kit</td>
   <td><input
         type="text"
         name="FieldData3_qty"
         size="2"
         onchange="orderTotal(this.form, 'FieldData3')"
         ></input></td>
   <td><input type="hidden" name="FieldData3_price" value="30.00"></input>RM 30.00</td>
   <td align="right">
      <input type="hidden" name="FieldData3_stHold"></input>
      <input
         type="text"
         name="FieldData3_stVis"
         size="7"
         onchange="visTotal(this.form, 'FieldData3')"
         ></input></td>
   </tr>

<!-- Wudu Kit -->
<tr>
   <td>Portable Wudu Kit</td>
   <td><input
         type="text"
         name="FieldData4_qty"
         size="2"
         onchange="orderTotal(this.form, 'FieldData4')"
         ></input></td>
   <td><input type="hidden" name="FieldData4_price" value="6.00"></input>RM 6.00</td>
   <td align="right">
      <input type="hidden" name="FieldData4_stHold"></input>
      <input
         type="text"
         name="FieldData4_stVis"
         size="7"
         onchange="visTotal(this.form, 'FieldData4')"
         ></input></td>
   </tr>
<tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <th>Totals</th>
   <td align="right">
   <input
   type="text"
   name="FieldData5_stVis"
   size="7"
   onchange="calcTotal(this.form, 'FieldData5')"
   ></input></td>
</tr>
</table>
</body>
</html>


Last edited by iamhaziq on Mon Feb 02, 2009 1:09 pm; edited 1 time in total
PayneLess Designs



Joined: 28 Feb 2007
Posts: 4289
Location: MS

PostPosted: Sat Jan 24, 2009 10:56 pm     Reply with quote

Calculating Order Form Totals
Calculating Order Form Totals 2
iamhaziq



Joined: 24 Jan 2009
Posts: 3

PostPosted: Mon Feb 02, 2009 1:12 pm     Reply with quote

That solves it! Thank you so much.
PayneLess Designs



Joined: 28 Feb 2007
Posts: 4289
Location: MS

PostPosted: Tue Feb 03, 2009 10:15 am     Reply with quote

You're welcome. Glad I could help.
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum -> Javascript All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
DARFUR
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial