刷新Javascript变量,无需重新加载页面

时间:2011-08-25 22:04:29

标签: javascript innerhtml

我有这个表单,里面有一个选择列表框。它显示了当用户选择不同选项时将改变的总数:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="paypal">
                                               <input type="hidden" name="cmd" value="_cart">
                                               <input type="hidden" name="upload" value="1">
                                               <input type="hidden" name="currency_code" value="GBP">
                                               <input type="hidden" name="business" value="contact@contact.org">   
                                            <select name="handling_cart" onChange="refresh();" style="margin-bottom: 5px;">
                                            <option selected value="10.00">UK £10.00</option>
                                            <option value="30.00">France £30.00</option>
                                            <option value="35.00">Germany £35.00</option>
                                            </select>                               
                                            </td>
                                        </tr>
                                        <tr>
                                        <td>Grand Total:</td>
                                        <td>£
                                        <script lanuage="JavaScript">                                           


                                        var delivery = document.paypal.handling_cart.value;

                                        var total = parseInt(jtotal)+parseInt(delivery); 
                                        document.write(total);
                                        </script></td>
                                        </tr> 

我没有刷新函数()但是我猜我需要一个?

TIA

1 个答案:

答案 0 :(得分:2)

好的,为你创建了refresh()。工作演示在这里http://jsfiddle.net/hwwDj/3/

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="paypal">
                                               <input type="hidden" name="cmd" value="_cart">
                                               <input type="hidden" name="upload" value="1">
                                               <input type="hidden" name="currency_code" value="GBP">
                                               <input type="hidden" name="business" value="contact@contact.org">   
                                            <select name="handling_cart" onChange="refresh();" style="margin-bottom: 5px;">
                                            <option selected value="10.00">UK £10.00</option>
                                            <option value="30.00">France £30.00</option>
                                            <option value="35.00">Germany £35.00</option>
                                            </select>                               
                                            </td>
                                        </tr>
                                        <tr>
                                        <td>Grand Total:</td>
                                            <td><div id="etd">£</div></td>
                                            </tr> 
                                        <script lanuage="javascript">                                           
var jtotal=10;

                                        var delivery = document.paypal.handling_cart.value;
                                            function refresh()
                                            {
                                                  delivery = document.paypal.handling_cart.value;
                                        var total = parseInt(jtotal)+parseInt(delivery); 
   document.getElementById("etd").innerHTML="£ "+total;
                                            }


                                            //document.write(total);
                                        </script>