该阵列添加上未通过对收银台进行 [英] The array add on isn't carried through to the checkout

查看:149
本文介绍了该阵列添加上未通过对收银台进行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以如果客户选择1礼物,1项产品和英国在下拉菜单的价格加起来是18.48£但是当他们在一定的岗位code类型(数组中列出),它应该添加额外的£2.00总使它£20.48它一样。但是,当pressing结帐只携带了18.48的£....这是因为数组没有添加到下面的公式总和?

 <脚本>
    函数myFunction的(PC){
        变种交code_arr = [ZE,KW,第四,HS,AB,DD,PH,PA,FK,KY,G ,BT,即时消息,GY,日本脑炎,EH,ML,KA];
        变种firsttwo = pc.substr(0,2);
        firsttwo = firsttwo.toUpperCase();
        //警报(firsttwo);        VAR一个=交code_arr.indexOf(firsttwo);
        如果(一个!= -1){
            VAR AMT = parseFloat(的document.getElementById(额)值。);
            AMT + = 2;
            。的document.getElementById(额)值= AMT;
        }        的document.getElementById(演示)的innerHTML =一。
    }
< / SCRIPT>
<形式的行动=htt​​ps://secure-test.worldpay.com/wcc/purchase方法=后NAME =BuyForm>
    <输入类型=隐藏的名字=instIdVALUE =000000><! - 在instId价值0000000,应与商家自己安装ID替换 - >
    <输入类型=隐藏的名字=cartIdVALUE =ABC123><! - 这是一个唯一的标识符为商户使用。例如:PRODUCT123 - >
    <输入类型=隐藏的名字=货币值=GBP><! - 选择适当的货币,你想用 - >
    <输入类型=隐藏的名字=降序VALUE =>
    <输入类型=隐藏的名字=TESTMODEVALUE =100>    < SCRIPT LANGUAGE =JavaScript的>        //接下来的两个函数一轮号码的数字格式。他们不需要添加或删除产品时,被改变。
        功能舍入(价值precision){
            返回的地方(价值1,precision);
        }        函数的地方(X,M,N){
            变种T,S =新的String(Math.round(X *号(1E+ N)))            而(S.length&下,M + N),S ='0'+ S
            变种Y = S.substr(0,T =(S.length - N));
            如果(N 0){
                Y + ='。 + S.substr(T,N);
            }            返回是;
        }        //这个空量功能的检查。它并不需要添加或删除产品时,被改变。
        功能CheckNull(值){
            如果(价值==){
                值=0;
            }            返回值;
        }        //这个函数定义了邮资和包装位置。它并不需要添加或删除产品时,被改变。
        功能typeOfCarriage(X,去向){
            的console.log(下落);
            x.carriage_amount.value =下落;
        }        //这个函数addeds邮资和包装产品的总价格。添加新的邮政资费这里,并且还进一步修改了网页,将其添加到表中。
        函数计算(X){
            basicprice =计算(X);
            如果(号码(basicprice)大于0){
                的console.log(basicprice);                开关(x.carriage_amount.value){
                    案UK:
                        postage_and_packaging = 3.50;
                        打破
                    案美国:
                        postage_and_packaging = 20.38;
                        打破
                        //要添加新的邮资。从这里复制...
                    案亚洲:
                        postage_and_packaging = 5.75;
                        打破
                        // ...到了这里,并直接贴上下方。改变国家的情况下,贴邮票的价格。您还需要添加你进一步创造了网页的邮资选项。
                    默认:
                        postage_and_packaging = 8.75;
                        打破;
                }
                x.amount.value = basicprice +电话号码(postage_and_packaging);            }
            其他{
                x.amount.value =0;
            }            x.amount.value =舍入(x.amount.value,2);
        }        //标准价格,exluding邮资和包装这里计算的。它并不需要添加或删除产品时,被改变。 - >
        函数计算(X){
            x.amount.value = 0;
            变种Y = x.price.length;
            变种Z = x.qty.length;
            VAR一个=号(x.amount.value);
            变种B,C;            而(γ大于0){
                B =号(CheckNull(x.price [Y - 1] .value的));
                C =号码(CheckNull(x.qty [Y - 1] .value的));
                A + =(B * C);
                y--;
            }
            返回;
        }
    < / SCRIPT>    < H1>邮资和放大器;放大器;包装< / H1>    <! - 此表提供列出的产品布局。 - >
    <表格的cellpadding =3BORDER =2ALIGN =中心>
        &所述; TR>
            < TD合并单元格=3>< B>个人消息(手写由Mr.F自己)LT; / B><输入名称=价格型=隐藏值=3.99> - &安培;磅; 3.99< / TD>
        < / TR>
        &所述; TR>
            < TD>数量:其中,输入名称=数量大小=3值=0>< / TD>
        < / TR>
        &所述; TR>
            < TD合并单元格=3>< B> 195点¯x295 Pixboard< / B><输入名称=价格型=隐藏值=10.99> - &安培;磅; 10.99< / TD>
        < / TR>
        &所述; TR>
            < TD>数量:其中,输入名称=数量大小=3值=1>< / TD>
        < / TR>
    < /表>    < BR>< BR>    < D​​IV ID =PM>
        &所述p为H.; < B>个人消息< / B> &所述; / P>
        &所述p为H.; (这会如果你这么上述规定只能写)LT; / P>
        &所述p为H.;你有140个字符℃的限制; / P>
        <输入ID =PMTB类型=文本行=2NAME =个人消息MAXLENGTH =140>< BR>
    < / DIV>    &所述;! - 该表被用作总计算器和邮资和包装的选择器。 - >
    &所述p为H.;
        < D​​IV ID =选择>
            <输入名称=carriage_amount类型=隐藏值=英国>
            <选择名称= postage_and_packaging的onchange =typeOfCarriage(this.form,THIS.VALUE);计算(this.form)>
                <选项选择的值=>请选择国家< /选项>            < /选择>    &所述p为H.; <输入名称=calcButton的onclick =计算(this.form)类型=按钮值=计算总> &所述; / P>
    &所述p为H.;
        < B>总计:放大器;磅; < / B><输入ID =量NAME =量大小= 8值=0>
    &所述; / P>    < / DIV>
    &所述; / P>
    < D​​IV ID =纲要>
        < P>< B>&要点LT; / B>< / P>
        <表ID =HVALIGN =中心>
            &所述; TR>
                &所述; TD>
                    <输入类型=复选框NAME =自由笔VALUE =自由笔>免费的笔和LT; BR>                    (你只会recive这一点,如果Mr.F心不是写你的个人信息)
                    &所述p为H.;&下; / P>
                < / TD>
            < / TR>
            &所述; TR>
                &所述; TD>
                    <输入类型=复选框NAME =水平值=水平>水平和LT; BR>
                < / TD>
            < / TR>
            &所述; TR>
                &所述; TD>
                    要么
                < / TD>
            < / TR>
            &所述; TR>
                &所述; TD>
                    <输入类型=复选框NAME =垂直值=垂直>垂直< BR>
                < / TD>
            < / TR>
        < /表>
    < / DIV>
    < D​​IV ID =PDF>        < B>物流详情< / B>
        &所述p为H.;
            <标签>全名< /标签>
            <输入类型=文本名称=全名所需的>        &所述p为H.;
            <标签>手机号码和LT; /标签>
            <输入类型=文本名称=手机号码>        &所述; / P>
        &所述p为H.;
            <标签>家庭电话< /标签>
            <输入类型=文本名称=家庭电话要求>        &所述; / P>
        &所述p为H.;
            <标签>电子邮件和LT; /标签>
            <输入类型=文本名称=电子邮件所需的>        &所述; / P>        < B>归属地址LT; / B>
        &所述p为H.;
            <标签>地址< /标签>
            <输入类型=文本名称=地址需要>
        &所述p为H.;
            <标签>城市与LT; /标签>
            <输入类型=所需的&GT文本名称=市/镇;
        &所述; / P>
        &所述p为H.;
            <标签>城市< /标签>
            <输入类型=所需的&GT文本名称=市/镇;
        &所述; / P>
        &所述p为H.;
            <标签>国家< /标签>
            <输入类型=文本名称=国家需要>
        &所述; / P>
        &所述p为H.;
            < B>邮政code< / B><输入名称=后code型=文本要求的onblur =myFunction的(THIS.VALUE);>
        &所述p为H.;
        &所述; / P>        < B>公司地址:LT; / B>
        &所述p为H.;
            <标签>地址< /标签>
            <输入类型=文本名称=地址>
        &所述p为H.;
            <标签>城市与LT; /标签>
            <输入类型=文本名称=市/镇>
        &所述; / P>
        &所述p为H.;
            <标签>城市< /标签>
            <输入类型=文本名称=市/镇>
        &所述; / P>
        &所述p为H.;
            <标签>国家< /标签>
            <输入类型=文本名称=国家>
        &所述; / P>
        &所述p为H.;
            < B>邮政code< / B><输入名称=后code型=文本的onblur =myFunction的(THIS.VALUE);>
        &所述p为H.;
        &所述; / P>        < B>礼品地址< / B>
        &所述p为H.;
            <标签>地址< /标签>
            <输入类型=文本名称=地址>
        &所述p为H.;
            <标签>城市与LT; /标签>
            <输入类型=文本名称=市/镇>
        &所述; / P>
        &所述p为H.;
            <标签>城市< /标签>
            <输入类型=文本名称=市/镇>
        &所述; / P>
        &所述p为H.;
            <标签>国家< /标签>
            <输入类型=文本名称=国家>
        &所述; / P>
        &所述p为H.;
            < B>邮政code< / B><输入名称=后code型=文本的onblur =myFunction的(THIS.VALUE);>
        &所述p为H.;
        &所述; / P>    < / DIV>
    <中心及GT;
        < P>< B>不要忘记上传图片< / B>< / P>
    < /中心及GT;    <! - 这会产生一个按钮,提交信息和发送用户进入WorldPay的付款页面。 - >
    < p ALIGN =中心><输入类型=提交值=结帐的onclick =计算(this.form)>< / P>
< /表及GT;


解决方案

这是一种很难理解什么是所有的事情在这里,但似乎 myFunction的只得到呼吁后code元素的模糊。这意味着它必须被首先选择,然后取消选择,这将触发的模糊。
我的猜测是此触发器将不会发生。所以,你必须确保 myFunction的无论被调用,用后code输入元素的当前值。

Okay so if the customer selects 1 gift, 1 product and UK in the drop down menu the price adds up to £18.48 but when they type in a certain post code (listed in the array) it should add an extra £2.00 to the total making it £20.48 which it does. But when pressing checkout it only carries over the £18.48.... is this because the array is not added into the formula below for the total sum?

<script>
    function myFunction(pc) {
        var postcode_arr = ["ZE", "KW", "IV", "HS", "AB", "DD", "PH", "PA", "FK", "KY", "G", "BT", "IM", "GY", "JE", "EH", "ML", "KA"];
        var firsttwo = pc.substr(0, 2);
        firsttwo = firsttwo.toUpperCase();
        //alert(firsttwo);

        var a = postcode_arr.indexOf(firsttwo);
        if (a != -1) {
            var amt = parseFloat(document.getElementById("amount").value);
            amt += 2;
            document.getElementById("amount").value = amt;
        }

        document.getElementById("demo").innerHTML = a;
    }
</script>
<form action="https://secure-test.worldpay.com/wcc/purchase" method="post" name="BuyForm">
    <input type="hidden" name="instId" value="000000"><!-- 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">

    <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) {
                console.log(basicprice);

                switch (x.carriage_amount.value) {
                    case "UK":
                        postage_and_packaging = 3.50;
                        break
                    case "US":
                        postage_and_packaging = 20.38;
                        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 = 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 &amp; Packaging</h1>

    <!-- This table provides layout for the products listed. -->
    <table cellpadding="3" border="2" align="center">
        <tr>
            <td colspan="3"><b>Personal Message (Hand Written by Mr.F Himself)</b><input name="price" type="hidden" value="3.99"> - &pound;3.99</td>
        </tr>
        <tr>
            <td>Quantity: <input name="qty" size="3" value="0"></td>
        </tr>
        <tr>
            <td colspan="3"><b>195 x 295 Pixboard</b><input name="price" type="hidden" value="10.99"> - &pound;10.99</td>
        </tr>
        <tr>
            <td>Quantity: <input name="qty" size="3" value="1"></td>
        </tr>
    </table>

    <br><br>

    <div id="PM">
        <p> <b>Personal Message</b> </p>
        <p> (This will only be written if you've specified so above) </p>
        <p> You have a limit of 140 Characters </p>
        <input id="PMTB" type="text" rows="2" name="Personal Message" maxlength="140"><br>
    </div>

    <!-- This table is used as the total calculator and postage and packaging selector. -->
    <p>
        <div id="Select">
            <input name="carriage_amount" type="hidden" value="uk">
            <select name=postage_and_packaging onchange="typeOfCarriage(this.form,this.value);calculate(this.form)">
                <option selected value="">Please select country</option>

            </select>

    <p> <input name="calcButton" onclick="calculate(this.form)" type=button value="Calculate Total"> </p>
    <p>
        <b>Total: &pound; </b><input id="amount" name="amount" size=8 value="0">
    </p>

    </div>
    </p>
    <div id="Essentials">
        <p><b>Essentials</b></p>
        <table id="HV" align="center">
            <tr>
                <td>
                    <input type="checkbox" name="Free Pen" value="Free Pen"> Free Pen<br>

                    ( You will only recive this if Mr.F isnt writing your personal message )
                    <p></p>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="checkbox" name="Horizontal" value="Horizontal"> Horizontal<br>
                </td>
            </tr>
            <tr>
                <td>
                    or
                </td>
            </tr>
            <tr>
                <td>
                    <input type="checkbox" name="Vertical" value="Vertical"> Vertical<br>
                </td>
            </tr>
        </table>
    </div>
    <div id="PDF">

        <b>Delivery Details</b>
        <p>
            <label>Full Name</label>
            <input type="text" name="Full Name" required>

        <p>
            <label>Mobile Number</label>
            <input type="text" name="Mobile Number">

        </p>
        <p>
            <label>Home Phone</label>
            <input type="text" name="Home Phone" required>

        </p>
        <p>
            <label>Email</label>
            <input type="text" name="Email" required>

        </p>

        <b>Home Address</b>
        <p>
            <label>Address</label>
            <input type="text" name="Address" required>
        <p>
            <label>Town</label>
            <input type="text" name="Town/City" required>
        </p>
        <p>
            <label>City</label>
            <input type="text" name="Town/City" required>
        </p>
        <p>
            <label>Country</label>
            <input type="text" name="Country" required>
        </p>
        <p>
            <b>Post Code</b><input name="postcode" type="text" required onblur="myFunction(this.value);">
        <p>
        </p>

        <b>Business Address</b>
        <p>
            <label>Address</label>
            <input type="text" name="Address">
        <p>
            <label>Town</label>
            <input type="text" name="Town/City">
        </p>
        <p>
            <label>City</label>
            <input type="text" name="Town/City">
        </p>
        <p>
            <label>Country</label>
            <input type="text" name="Country">
        </p>
        <p>
            <b>Post Code</b><input name="postcode" type="text" onblur="myFunction(this.value);">
        <p>
        </p>



        <b>Gift Address</b>
        <p>
            <label>Address</label>
            <input type="text" name="Address">
        <p>
            <label>Town</label>
            <input type="text" name="Town/City">
        </p>
        <p>
            <label>City</label>
            <input type="text" name="Town/City">
        </p>
        <p>
            <label>Country</label>
            <input type="text" name="Country">
        </p>
        <p>
            <b>Post Code</b><input name="postcode" type="text" onblur="myFunction(this.value);">
        <p>
        </p>

    </div>
    <center>
        <p><b>Dont forget to upload your image</b></p>
    </center>

    <!-- 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>

解决方案

It's kind of hard to understand what's all going on here, but it seems that the myFunction only gets called on the blur of the postcode element. Meaning it has to be selected first, then deselected, which triggers the blur. My guess is this trigger won't happen. So you have to make sure the myFunction gets called regardless, with the current value of the postcode input element.

这篇关于该阵列添加上未通过对收银台进行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆