基本上,价格计算器不断提出“N.Na”而不是产品+ P& P.我似乎无法理解为什么它不起作用,仍在学习javascript和HTML,但据我所知,一切都在正确的地方?感谢您查看并提前发布任何答案。
<!-- HTML Select Junior Example 0.4 -->
<!-- Please note the code on these pages are provided by WorldPay as working examples only. -->
<!-- Any changes you make to the copies of these pages will not be supported by WorldPay. -->
<!-- For further information on reading html see the supplied help section. -->
<html>
<!-- The name, style, and properties of the page are defined in the 'head' tags -->
<head>
<title>HTML Redirect Example 0.4</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Junior HTML Example 0.4">
<meta name="keywords" content="Junior, html">
<style type="text/css"> td {text-align:"left"; vertical-align:"middle"; font-family:"arial"; color:"black"} h1,h2,h3,h4,h5,h6,h7 {text-align:"center"; vertical-align:"middle"; font-family:"arial"; color:"black"}</style>
</head>
<!-- The content to be used on the page is placed between the 'body' tags. -->
<body>
<!-- This is a purchase token, for more information on the elements with in a purchase token see the supplied help section. -->
<!-- PLEASE NOTE: this is a test installation and values will require changing to reflect merchants requirements -->
<form action="https://secure-test.worldpay.com/wcc/purchase" method=post name=BuyForm">
<input type="hidden" name="instId" value="211616"><!-- The "instId" value "0000000" should be replaced with the Merchant's own installation Id -->
<input type="hidden" name="cartId" value="abc123"><!-- This is a unique identifier for merchants use. Example: PRODUCT123 -->
<input type="hidden" name="currency" value="GBP"><!-- Choose appropriate currency that you would like to use -->
<input type="hidden" name="desc" value="">
<input type="hidden" name="testMode" value="100">
<!-- JavaScript is used to give functionality to some of the pages elements -->
<script language="JavaScript">
<!-- The next two functions round numbers to numerical formatting. They do not need to be altered when adding or removing products. -->
function roundOff(value, precision)
{
return places(value,1,precision);
}
function places(X, M, N)
{
var T, S=new String(Math.round(X*Number("1e"+N)))
while (S.length<M+N) S='0'+S
var y = S.substr(0, T=(S.length-N));
if(N>0)
{
y += '.' + S.substr(T, N);
}
return y;
}
<!-- This function checks for empty quantities. It does not need to be altered when adding or removing products. -->
function CheckNull(value)
{
if (value == "")
{
value = "0";
}
return value;
}
<!-- This function defines the postage and packaging location. It does not need to be altered when adding or removing products. -->
function typeOfCarriage(x,whereabouts)
{
x.carriage_amount.value = whereabouts;
}
<!-- This function addeds the postage and packaging to the total price of the products. Add new postage rates here, and also edit further down the page to add them to the table. -->
function calculate(x)
{
basicprice = calc(x);
if(Number(basicprice) > 0)
{
switch (x.carriage_amount.value)
{
case "uk" :
x.postage_and_packaging.value = 2.75;
break
case "europe" :
x.postage_and_packaging.value = 4.75;
break
case "usa" :
x.postage_and_packaging.value = 5.75;
break
<!-- To add a new postage rate. Copy from here... -->
case "asia" :
x.postage_and_packaging.value = 5.75;
break
<!-- ...to here, and paste directly below. Change the case country, and the postage price. You will also need to add the postage option you have created further down the page. -->
default :
x.postage_and_packaging.value = 8.75;
break;
}
x.amount.value = Number(basicprice) + Number(x.postage_and_packaging.value);
}
else
{
x.amount.value = "0";
}
x.amount.value = roundOff(x.amount.value,2);
}
<!-- The standard price, exluding postage and packaging is calculated here. It does not need to be altered when adding or removing products. -->
function calc(x)
{
x.amount.value = 0;
var y = x.price.length;
var z = x.qty.length;
var a = Number(x.amount.value);
var b,c;
while(y > 0)
{
b = Number(CheckNull(x.price[y-1].value));
c = Number(CheckNull(x.qty[y-1].value));
a += (b * c);
y--;
}
return a;
}
</script>
<h1>Postage & Packaging</h1>
<!-- This table provides layout for the products listed. -->
<table cellPadding="3" border=2 align="center">
<tr>
<td colSpan=3><b>Product 1</b><input name="price" type="hidden" value="10.00"> - £10.00</td>
</tr>
<tr>
<td>Quantity: <input name="qty" size="3" value="0""></td>
</tr>
<tr>
<td colSpan=3><b>Product 2</b><input name="price" type="hidden" value="15.00"> - £15.00</td>
</tr>
<tr>
<td>Quantity: <input name="qty" size="3" value="0"></td>
</tr>
</table>
<br><br>
<!-- This table is used as the total calculator and postage and packaging selector. -->
<input name=carriage_amount type=hidden value=uk>
<table cellPadding="3" border=2 align="center">
<tr>
<td><b>Postage &<br>Packaging:</b></td>
<td><input checked name="postage_and_packaging" onclick="typeOfCarriage(this.form,'uk');calculate(this.form)" type=radio value=""><B>UK</B> (£2.75)</td>
<td><input name="postage_and_packaging" onclick="typeOfCarriage(this.form,'europe');calculate(this.form)" type=radio value=""><b>Europe</b> (£4.75)</td>
<td><input name="postage_and_packaging" onclick="typeOfCarriage(this.form,'usa');calculate(this.form)" type=radio value=""><b>USA</b> (£5.75)</td>
<!-- To add a new postage rate copy from here... -->
<!-- ...to here, pasting directly below. Change the typeOfCarridge(country), and the price. -->
<td><input name=postage_and_packaging onclick="typeOfCarriage(this.form,'world');calculate(this.form)" type=radio value=""><b>Rest of World</b> (£8.75)</td>
</tr>
<tr>
<!-- This line generates a button that calculates the cost of the whole order. It does not need to be altered when adding or removing products. -->
<td colspan="3" style="text-align:center"><input name="calcButton" onclick="calculate(this.form)" type=button value="Calculate Total"></td>
<td COLSPAN="3" style="text-align:center"><b>Total: £ </b><input name="amount" size=4 value="0"></td>
</tr>
</table>
</td>
</tr>
</table>
<!-- This generates a button that submits the information and send the user into the Worldpay payment pages. -->
<p align="center"><input type=submit value=Checkout onclick="calculate(this.form)"></p>
</form>
</body>
</html>
答案 0 :(得分:0)
这里是整个代码,无法在代码预览中使用
<!-- This is a purchase token, for more information on the elements with in a purchase token see the supplied help section. -->
<!-- PLEASE NOTE: this is a test installation and values will require changing to reflect merchants requirements -->
<form action="https://secure-test.worldpay.com/wcc/purchase" method=post name=BuyForm">
<input type="hidden" name="instId" value="211616"><!-- The "instId" value "0000000" should be replaced with the Merchant's own installation Id -->
<input type="hidden" name="cartId" value="abc123"><!-- This is a unique identifier for merchants use. Example: PRODUCT123 -->
<input type="hidden" name="currency" value="GBP"><!-- Choose appropriate currency that you would like to use -->
<input type="hidden" name="desc" value="">
<input type="hidden" name="testMode" value="100">
<!-- JavaScript is used to give functionality to some of the pages elements -->
<script language="JavaScript">
<!-- The next two functions round numbers to numerical formatting. They do not need to be altered when adding or removing products. -->
function roundOff(value, precision)
{
return places(value,1,precision);
}
function places(X, M, N)
{
var T, S=new String(Math.round(X*Number("1e"+N)))
while (S.length<M+N) S='0'+S
var y = S.substr(0, T=(S.length-N));
if(N>0)
{
y += '.' + S.substr(T, N);
}
return y;
}
<!-- This function checks for empty quantities. It does not need to be altered when adding or removing products. -->
function CheckNull(value)
{
if (value == "")
{
value = "0";
}
return value;
}
<!-- This function defines the postage and packaging location. It does not need to be altered when adding or removing products. -->
function typeOfCarriage(x,whereabouts)
{
console.log(whereabouts);
x.carriage_amount.value = whereabouts;
}
<!-- This function addeds the postage and packaging to the total price of the products. Add new postage rates here, and also edit further down the page to add them to the table. -->
function calculate(x)
{
basicprice = calc(x);
if(Number(basicprice) > 0)
{
switch (x.carriage_amount.value)
{
case "uk" :
postage_and_packaging = 2.75;
break
case "europe" :
postage_and_packaging = 4.75;
break
case "usa" :
postage_and_packaging = 5.75;
break
<!-- To add a new postage rate. Copy from here... -->
case "asia" :
postage_and_packaging = 5.75;
break
<!-- ...to here, and paste directly below. Change the case country, and the postage price. You will also need to add the postage option you have created further down the page. -->
default :
postage_and_packaging = 8.75;
break;
}
x.amount.value = parseInt(basicprice) + Number(postage_and_packaging);
}
else
{
x.amount.value = "0";
}
x.amount.value = roundOff(x.amount.value,2);
}
<!-- The standard price, exluding postage and packaging is calculated here. It does not need to be altered when adding or removing products. -->
function calc(x)
{
x.amount.value = 0;
var y = x.price.length;
var z = x.qty.length;
var a = Number(x.amount.value);
var b,c;
while(y > 0)
{
b = Number(CheckNull(x.price[y-1].value));
c = Number(CheckNull(x.qty[y-1].value));
a += (b * c);
y--;
}
return a;
}
</script>
<h1>Postage & Packaging</h1>
<!-- This table provides layout for the products listed. -->
<table cellPadding="3" border=2 align="center">
<tr>
<td colSpan=3><b>Product 1</b><input name="price" type="hidden" value="10.00"> - £10.00</td>
</tr>
<tr>
<td>Quantity: <input name="qty" size="3" value="0""></td>
</tr>
<tr>
<td colSpan=3><b>Product 2</b><input name="price" type="hidden" value="15.00"> - £15.00</td>
</tr>
<tr>
<td>Quantity: <input name="qty" size="3" value="0"></td>
</tr>
</table>
<br><br>
<!-- This table is used as the total calculator and postage and packaging selector. -->
<input name=carriage_amount type=hidden value=uk>
<table cellPadding="3" border=2 align="center">
<tr>
<td>
<select name=postage_and_packaging onchange="typeOfCarriage(this.form,this.value);calculate(this.form)">
<option Value=''>Ship To</option>
<option Value='uk'>UK</option>
<option Value='europe'>Europe</option>
<option Value='usa'>US</option>
<option Value='asia'>Rest of the World</option>
</select>
<p>
<input name="calcButton" onclick="calculate(this.form)" type=button value="Calculate Total">
<p>
<b>Total: £ </b><input name="amount" size=4 value="0">
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- This generates a button that submits the information and send the user into the Worldpay payment pages. -->
<p align="center"><input type=submit value=Checkout onclick="calculate(this.form)"></p>