[thelist] multi-use javascript form update function

Joel Canfield joel at bizba6.com
Mon Sep 14 21:00:54 CDT 2009

My memories of javascript are faded.
I have three PayPal buttons on a page; each form allows the user to choose a
quantity, and domestic or foreign shipping. When the quantity is selected or
the shipping radio button changed, the form updates the shipping amount and
quantity in the form.

With one form, I had it working. With three, my never-strong js skills are
out of their depth. Pointers for making this code work with all three forms
would be great.

the function:

function updateShipping()
document.form.quantity.value = document.form.QtyCE.value
var ShippingRate = 0;
for(i = 0; i < document.form.ShippingLocation.length; i++)
if(document.form.ShippingLocation[i].checked == true)
ShippingRate = document.form.ShippingLocation[i].value;
var ShippingQuantity = 2;
if(document.form.QtyCE.value > 2)
ShippingQuantity = document.form.QtyCE.value
document.form.shipping.value = (ShippingRate * 1) + ((ShippingQuantity - 2)
* (ShippingRate/4))

and three forms very much like this, but the select id and the shipping
location radio buttons are IDed differently in each

<form name="BuyCEpaperback" id="BuyCEpaperback" action="
https://www.paypal.com/cgi-bin/webscr" method="post">
<p>Please send me <select name="CEQty" id="QtyCEpaperback"
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select> copies of <em>The Commonsense Entrepreneur (paperback)</em> to be
shipped<br />
<input type="radio" name="ShippingLocation" id="ContinentalUS" value="4"
checked onchange="updateShipping();" /><label for="ContinentalUS">
<strong>within</strong> the Continental US</label><br />
<input type="radio" name="ShippingLocation" id="International" value="8"
onchange="updateShipping();" /><label for="International">
<strong>outside</strong> the Continental US</label><br />

clearly, I have to tell the function which form to talk to; that's one of
the many things I'm fuzzy about here

Joel at Bizba6.com

More information about the thelist mailing list