0

I have this form with a select list box in it. It shows a total that will change when the user selects different options:

<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="[email protected]">   
                                            <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> 

I haven't got a function refresh() but I'm guessing I'm going to need one?

TIA

1
  • You probaly want to do event binding here and have a callback function that will update your ui.. Commented Aug 25, 2011 at 22:08

1 Answer 1

2

Okay, created refresh() for you. Working demo is here 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="[email protected]">   
                                            <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>
Sign up to request clarification or add additional context in comments.

4 Comments

Might not have been clear enough, I want the total in docuement.write(total) to update without reloading the page. No alert just the value on the plain page. Thanks for the answer anyhow.
Which value's total you want to add with delivery? Make the thing clear. If you mean jtotal, its not defined in the code.
Its not in that little snippet, but it is in there way up the code.
OK I assume jtotal=10, so now I have edited my code above, also you can check here jsfiddle.net/hwwDj/3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.