altid 2 decimaler
Jeg vil gerne at dette script altid skriver 2 decimaler ergo når resultatet er 5.5 skal den skrive 5.50 Hvordan???<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
<!-- Minus AutoDato -->
<HTML><HEAD><TITLE>Bestillingsform</TITLE>
<META NAME=\"Generator\" CONTENT=\"Stone\'s WebWriter 3.5\">
<META content=\"text/html; charset=iso-8859-1\" http-equiv=Content-Type>
<META content=\"Microsoft FrontPage 4.0\" name=GENERATOR>
<STYLE type=text/css>
BODY
{
BACKGROUND-COLOR: white
}
.mainTable
{
BACKGROUND-COLOR: white;
WIDTH: 400px;
BORDER-STYLE: solid;
border-color: blue;
border-width: 2px;
}
.subTable
{
BACKGROUND-COLOR: white;
WIDTH: 100%;
BORDER-STYLE: black solid 1px;
MARGIN: 1px;
}
.mainHeader
{
COLOR: black;
FONT-FAMILY: Arial, Verdana;
FONT-SIZE: xx-large;
FONT-WEIGHT: 500
}
.subHeader
{
COLOR: blue;
FONT-FAMILY: Arial, Verdana;
FONT-SIZE: medium;
FONT-WEIGHT: 600
}
.deliveryHeader
{
COLOR: black;
FONT-FAMILY: Arial, Verdana;
FONT-SIZE: x-small;
FONT-WEIGHT: 400;
}
.deliveryInput
{
COLOR: black;
FONT-FAMILY: Arial, Verdana;
FONT-SIZE: x-small;
FONT-WEIGHT: normal;
WIDTH: 250px;
}
.basketHeader
{
COLOR: black;
FONT-FAMILY: Arial, Verdana;
FONT-SIZE: x-small;
FONT-WEIGHT: 700
}
.productName
{
COLOR: black;
FONT-FAMILY: Arial, Verdana;
FONT-SIZE: x-small;
FONT-WEIGHT: normal
}
.productPrice
{
COLOR: black;
FONT-FAMILY: Arial, Verdana;
FONT-SIZE: x-small
}
.totalPriceHeader
{
COLOR: black;
FONT-FAMILY: Arial, Verdana;
FONT-SIZE: x-small;
FONT-WEIGHT: 500
}
.totalPrice
{
COLOR: black;
FONT-FAMILY: Arial, Verdana;
FONT-SIZE: x-small;
FONT-WEIGHT: 500;
BORDER-STYLE: none;
text-align: right;
WIDTH: 75px;
BORDER-STYLE: none;
}
.productCount
{
COLOR: black;
FONT-FAMILY: Arial, Verdana;
FONT-SIZE: x-small;
FONT-WEIGHT: normal;
WIDTH: 30px;
text-align: right;
}
.linePrice
{
COLOR: black;
FONT-FAMILY: Arial, Verdana;
FONT-SIZE: x-small;
FONT-WEIGHT: normal;
WIDTH: 75px;
BORDER-STYLE: none;
text-align: right;
}
</STYLE>
<SCRIPT language=JavaScript>
/*
Copyright by InterCool&Co - 2001
You need to obtain explicit permission to use this javascript orderform/basket
*/
//array indeholdende id\'er på input-felter med linie-priser
var lineItems = new Array(\'linePrice_1\',\'linePrice_2\',\'linePrice_3\',\'linePrice_4\',\'linePrice_5\')
//beregner prisen på en ordrelinie udfra indtastet antal og pris på det aktuelle produkt
function calculateOrderLine(product_id, linePrice_id, price) {
objProduct = eval(\"document.forms[\'Bestillingsform\'][\'\" + product_id + \"\']\")
objLinePrice = eval(\"document.forms[\'Bestillingsform\'][\'\" + linePrice_id + \"\']\")
calculated = price * objProduct.value
objLinePrice.value = calculated
//test på om det indtastede antal er et lovligt antal
if (isNaN(calculated)) {
objLinePrice.value = \"0\"
alert(\"Det indtastede skal være et tal\")
objProduct.value = \"0\"
} else {
calculated = calculated.toString()
decPos = calculated.indexOf(\".\")
if (decPos != -1) {
objLinePrice.value = calculated.substring(0,calculated.indexOf(\".\")+3)
} else {
calculated = calculated + \".00\"
objLinePrice.value = calculated
}
}
//beregn det totale beløb
calculateOrderTotal()
}
//beregner prisen på den samlede ordre
function calculateOrderTotal() {
totalAmount = 0;
//løb alle formularens elementer igennem og beregn den samlede pris
for (i=0; i<lineItems.length;i++) {
currentID = lineItems[i]
currentVal = eval(\"document.forms[\'Bestillingsform\'][\'\" + currentID + \"\'].value\")
totalAmount = totalAmount + parseFloat(currentVal)
}
//tilføj ordregebyr
if (totalAmount > 0) {
orderFee = eval(\"document.forms[\'Bestillingsform\'][\'Ordre gebyr\'].value\")
totalAmount = totalAmount + parseFloat(orderFee)
}
totalAmount = totalAmount.toString()
decPos = totalAmount.indexOf(\".\")
if (decPos != -1) {
totalAmount = totalAmount.substring(0,totalAmount.indexOf(\".\")+3)
} else {
totalAmount = totalAmount + \".00\"
}
totalPriceObj = eval(\"document.forms[\'Bestillingsform\'][\'Samlet pris\']\")
totalPriceObj.value = totalAmount
}
function validateOrderData() {
//er der valgt nogle produkter
total = document.forms[\'Bestillingsform\'][\'Samlet pris\'].value
if (total == \"\" || total == \'NaN\' || total == null || total == 0) {
alert(\"Der er ikke valgt varer på bestillingen!\")
return false
}
//er leverings info givet
if (document.forms[\'Bestillingsform\'][\'Navn\'].value == \'\') {
alert(\"Der skal indtastes et navn, hvortil bestillingen skal sendes\")
return false
} else if (document.forms[\'Bestillingsform\'][\'Adresse\'].value == \'\') {
alert(\"Der skal indtastes en adresse, hvortil bestillingen skal sendes\")
return false
} else if (document.forms[\'Bestillingsform\'][\'Postnr./By\'].value == \'\') {
alert(\"Der skal indtastes et postnr. og by, hvortil bestillingen skal sendes\")
return false
}
//bekræft ordre afgivelse
if (!confirmOrder()) {
return false
}
//validation ok
return true
}
function trimString() {
}
//bekræft ordre afgivelse
function confirmOrder() {
msg = \"Er du sikker på at du vil fuldføre bestillingen?\\n\\n\"
//Kurvens indhold listes
msg = msg + \"Du har bestilt følgende:\\n\\n\"
msg = msg + \"Cykel - \" + document.forms[\'Bestillingsform\'][\'Cykel\'].value + \" stk.\\n\"
msg = msg + \"Forlygte - \" + document.forms[\'Bestillingsform\'][\'Forlygte\'].value + \" stk.\\n\"
msg = msg + \"Baglygte - \" + document.forms[\'Bestillingsform\'][\'Baglygte\'].value + \" stk.\\n\"
msg = msg + \"Reflekser - \" + document.forms[\'Bestillingsform\'][\'Reflekser\'].value + \" stk.\\n\"
msg = msg + \"Racerstyr - \" + document.forms[\'Bestillingsform\'][\'Racerstyr\'].value + \" stk.\\n\\n\"
msg = msg + \"Til en samlet pris på kr. \" + document.forms[\'Bestillingsform\'][\'Samlet pris\'].value + \" inkl. ordregebyr på kr. \" + document.forms[\'Bestillingsform\'][\'Ordre gebyr\'].value + \"\\n\"
if (window.confirm(msg)) {
return true
} else {
return false
}
}
</SCRIPT>
</HEAD>
<BODY><P><SPAN class=mainHeader>Bestillingsform</SPAN>
<form action=\"http://formmail.digiweb.dk/script/FormMail.pl\" method=\"post\"
name=\"Bestillingsform\" onsubmit=\"return validateOrderData()\">
<input type=\"hidden\" name=\"recipient\" value=\"webmaster@ayurveda.dk\">
<TABLE class=mainTable>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=4>
<P align=center><SPAN class=subHeader>Levering</SPAN></P></TD></TR>
<TR>
<TD><SPAN class=deliveryHeader>Navn</SPAN></TD>
<TD colSpan=3><INPUT class=deliveryInput name=Navn></TD></TR>
<TR>
<TD><SPAN class=deliveryHeader>Adresse</SPAN></TD>
<TD colSpan=3><INPUT class=deliveryInput name=Adresse></TD></TR>
<TR>
<TD><SPAN class=deliveryHeader>Postnr./By</SPAN></TD>
<TD colSpan=3><INPUT class=deliveryInput name=Postnr./By></TD></TR>
<TR>
<TD><SPAN class=deliveryHeader>Telefon</SPAN></TD>
<TD colSpan=3><INPUT class=deliveryInput name=Telefon></TD></TR>
<TR>
<TD><SPAN class=deliveryHeader>Email</SPAN></TD>
<TD colSpan=3><INPUT class=deliveryInput name=Email></TD></TR>
<TR>
<TD><SPAN class=deliveryHeader>Kommentarer</SPAN></TD>
<TD
colSpan=3><TEXTAREA name=Kommentarer rows=\"1\" cols=\"20\"></TEXTAREA></TD></TR></TBODY></TABLE><BR>
<TABLE cellSpacing=10>
<TBODY>
<TR>
<TD colSpan=4>
<P align=center><SPAN class=subHeader>Bestilling</SPAN></P></TD></TR>
<TR>
<TD width=\"50%\"><SPAN class=basketHeader>Produkt</SPAN></TD>
<TD width=\"30%\"><SPAN class=basketHeader>Enhedspris</SPAN></TD>
<TD width=\"5%\"><SPAN class=basketHeader>Antal</SPAN></TD>
<TD align=right width=\"15%\"><SPAN
class=basketHeader>Pris</SPAN></TD></TR>
<TR>
<TD><SPAN class=productName>Cykel</SPAN></TD>
<TD><SPAN class=productPrice>Kr. 2.995,00</SPAN></TD>
<TD><INPUT class=productCount maxLength=2 name=Cykel
onchange=\"calculateOrderLine(\'Cykel\', \'linePrice_1\', 2995)\"
value=0></TD>
<TD align=right><INPUT class=linePrice disabled name=linePrice_1
onfocus=blur() value=0></TD></TR>
<TR>
<TD><SPAN class=productName>Forlygte</SPAN></TD>
<TD><SPAN class=productPrice>Kr. 17,95</SPAN></TD>
<TD><INPUT class=productCount maxLength=2 name=Forlygte
onchange=\"calculateOrderLine(\'Forlygte\', \'linePrice_2\', 17.95)\"
value=0></TD>
<TD align=right><INPUT class=linePrice disabled name=linePrice_2
onfocus=blur() value=0></TD></TR>
<TR>
<TD><SPAN class=productName>Baglygte</SPAN></TD>
<TD><SPAN class=productPrice>Kr. 17,95</SPAN></TD>
<TD><INPUT class=productCount maxLength=2 name=Baglygte
onchange=\"calculateOrderLine(\'Baglygte\', \'linePrice_3\', 17.95)\"
value=0></TD>
<TD align=right><INPUT class=linePrice disabled name=linePrice_3
onfocus=blur() value=0></TD></TR>
<TR>
<TD><SPAN class=productName>Reflekser</SPAN></TD>
<TD><SPAN class=productPrice>Kr. 5,00</SPAN></TD>
<TD><INPUT class=productCount maxLength=2 name=Reflekser
onchange=\"calculateOrderLine(\'Reflekser\', \'linePrice_4\', 5)\"
value=0></TD>
<TD align=right><INPUT class=linePrice disabled name=linePrice_4
onfocus=blur() value=0></TD></TR>
<TR>
<TD><SPAN class=productName>Racerstyr</SPAN></TD>
<TD><SPAN class=productPrice>Kr. 595,75</SPAN></TD>
<TD><INPUT class=productCount maxLength=2 name=Racerstyr
onchange=\"calculateOrderLine(\'Racerstyr\', \'linePrice_5\', 595.75)\"
value=0></TD>
<TD align=right><INPUT class=linePrice disabled name=linePrice_5
onfocus=blur() value=0></TD></TR>
<TR>
<TD colSpan=3><SPAN class=totalPriceHeader>Samlet pris (inkl.
ordregebyr på kr. 100,50)</SPAN></TD>
<TD><INPUT class=totalPrice disabled name=\"Samlet pris\"
onfocus=blur() value=0> <INPUT disabled name=\"Ordre gebyr\"
type=hidden value=100.50></TD></TR></TBODY></TABLE><BR>
<TABLE>
<TBODY>
<TR>
<TD>
<P align=center><INPUT id=reset name=reset1 type=reset value=\"Nulstil indtastninger\">
<INPUT id=submit name=submit1 type=submit value=\"Send bestilling\"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM>
<SCRIPT language=JavaScript>
//set fokus til første formularelement
//document.forms[\'Bestillingsform\'].name.focus();
</SCRIPT>
</BODY></HTML>