出于某种原因,此代码上的计算器赢得了'不起作用
For some reason the calculator on this code won't work?
基本上,价格计算器一直在计算"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>
这是整个代码,无法在代码预览中工作
<!-- 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>
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 监视函数从服务返回不起作用,但作用域函数起作用
- 幻灯片滚动javascript不起作用
- 简单的javascript在Shopify中不起作用
- Recaptcha在IE7和IE8中不起作用
- Javascript旅行计算器不起作用
- 简单的JS计算器-为什么不是'这个if语句不起作用
- 编程新手,可以'我不明白为什么这个因子计算器没有;不起作用
- 带有计算器的Javascript列表不起作用
- 提示计算器 jquery 不起作用
- JavaScript计算器脚本不起作用
- 为什么我的Javascript价格计算器不起作用
- 自制计算器不起作用
- Javascript计算器退格键第一次不起作用
- 为什么这个简单的HTML/JavaScript计算器不起作用
- 简单的 HTML/JavaScript 计算器不起作用
- JavaScript月计算器不起作用
- JS简单成绩计算器代码不起作用
- 出于某种原因,此代码上的计算器赢得了'不起作用
- PHP 做一个简单的计算器 - 代码不起作用