[thelist] multi-use javascript form update function

aardvark evolt at roselli.org
Tue Sep 15 07:30:52 CDT 2009


why not modify the function so that you pass in the id of the element 
you want to affect?

function updateShipping(elemID) {
var formItem = document.getElementById(elemID);
[...]
if(formItem.value > 2)
[...]

in your form just call the function with the appropriate element:
<input type="radio" onchange="updateShipping('QtyCEpaperback');" />

or is that not the thing you want to do with the form? is it the 
looping you want to do? you can take the same approach and just pass 
in another variable... i have to admit, i'm sending this while also 
doing a couple other things, so i may not be reading it clearly...

there are a lot of different ways to do this, but utlimately i 
recommend you just pass in the variants and treat them as variables 
within the function, this way you can re-use it over and over...

On 14 Sep 2009 at 19:00, Joel Canfield wrote:

> 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.
[...]
> clearly, I have to tell the function which form to talk to; that's one of
> the many things I'm fuzzy about here





More information about the thelist mailing list