Click to See Complete Forum and Search --> : using a variable in the DOM


vectorfrog
07-31-2008, 11:30 PM
Hi, I have a page with tons of forms (each represents a product) that look almost exactly alike, the only difference is the name of the form. I'd like to create a function that will reset the value of one of the hidden feillds in the form based on a dropdown box. I know how to do this by using the specific DOM reference such as:

document.testform.price.value = document.testform.size_choice.value;

however, since I have so many forms that use the exact same hidden and dropdown names (price and size_choice), is there a way I can create 1 function where I pass the different form names? For instance:

function setPrice(form_name){

document.form_name.price.value = document.form_name.size_choice.value;
}

I'm sure there must be a way, but I'm not having any luck finding it. Please forgive my newbiness ;)

the_swede
07-31-2008, 11:34 PM
Mmm...what about document.forms[]? Would that work? You could pass on each element in the array to the function.

vectorfrog
08-01-2008, 12:17 AM
That worked great. Please accept my humble obeisance toward your javascripting skills :D