|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I have the calculator running smoothly on my 'Actual Webpage', but i wanted to
know how it actually worked. So i started a new document and threw together a small 'form'. The HTML code you see below will appear as a small box/table thing, with 2 checkboxes. when you click on the checkboxes, the total is meant to add up in the 'total box'...but it doesnt seem to want to work. So, could someone tell me what im doing wrong. Im not a javascript pro, so be kind. Thanks <!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" xml:lang="en"> <head> <title>GreyBox - Examples</title> <script type="text/javascript"> var GB_ROOT_DIR ="Greybox/Greybox_v5_53/greybox/"; </script> <script type="text/javascript" src="Greybox/Greybox_v5_53/greybox/AJS.js"></script> <script type="text/javascript" src="Greybox/Greybox_v5_53/greybox/AJS_fx.js"></script> <script type="text/javascript" src="Greybox/Greybox_v5_53/greybox/gb_scripts.js"></script> <link href="Greybox/Greybox_v5_53/greybox/gb_styles.css" rel="stylesheet" type="text/css" media="all" /> </head> <body> <form method="post" name="orderform" enctype="text/plain"> <table border="0" bgcolor="#663F8F"> <tr bgcolor="#662F8F"><td colspan="2"> <p> <input type="checkbox" name="Item1" value="Item1_chosen" onclick="tally()" /> RM006 <p> <input type="checkbox" name="Item2" value="Item2_chosen" onclick="tally()" /> RM002</td></tr> <tr> <td><span class="style1"> Total <input type="text" name="Total" value="$0" size="7"> </span></td> </tr> <tr> <td><span class="style1"> Grand Total <input type="text" name="GrandTotal" value="$0" size="8"> </span></td> </tr> </table> </form> <script language="javascript"> var Cost, Grand_Total; function tally () { cost = 0; if (document.orderform.Item1.checked) { Cost = Cost + 17.00; } if (document.orderform.Item2.checked) { Cost = Cost + 4.00: } Cost = dollar(Cost); Grand_Total = parseFloat(Cost) Grand_Total = dollar(Grand_Total); document.orderform.Total.value = "$" + Cost; document.orderform.GrandTotal.value = "$" + Grand_Total; } function dollar (amount) { amount = parseInt(amount * 100); amount = parseFloat(amount/100); if (((amount) == Math.floor(amount)) && ((amount - Math.floor (amount)) == 0)) { amount = amount + ".00" return amount; } if ( ((amount * 10) - Math.floor(amount * 10)) == 0) { amount = amount + "0"; return amount; } if ( ((amount * 100) - Math.floor(amount * 100)) == 0) { amount = amount; return amount; } return amount; } //--> </script> </body> </html> |
|
![]() |
| Outils de la discussion | |
|
|