Click to See Complete Forum and Search --> : How to change a form name of the fly?


jshowe
07-07-2003, 10:28 PM
Hi,
I am very new and am trying to make a function that will update the value for multiple different elements. I need Product08 to be Product02, Product04, Product15, but not Product03 or Product05,etc... So I can't just use a for loop. Is there a way I can just make it a variable and have whatever calls to the function replace Product08 with it's name?

ie- if <select onchange=reCalc() name=Product02> Can I make Product02 take the place of Product08 on the fly???

BTW - Product08Total and the Other Product0XTotals are input boxes...

Thanks!!

function reCalc()
{
current=document.TheForm.Product08.selectedIndex;

thisValue =
document.TheForm.Product08.options[current].value;

document.TheForm.Product08Total.value = thisValue;
}

jshowe
07-07-2003, 11:46 PM
Let me see if explaining what I am trying to do will help...

I have 15 different drop down menus <SELECT> and 15 corrisponding <input>. When I make a selection in one of the dropdown menu I would like the value to be displayed in the input. I have gotten it to work when I reference the select and input with constants.... Is what I am looking for document.theform.elements[i]?? I can't seem to figure out how to make it work! Please help...
-Scott :confused:

jshowe
07-08-2003, 12:25 AM
Let me see if explaining what I am trying to do will help...

I have 15 different drop down menus <SELECT> and 15 corrisponding <input>. When I make a selection in one of the dropdown menu I would like the value to be displayed in the input. I have gotten it to work when I reference the select and input with constants.... Is what I am looking for document.theform.elements[i]?? I can't seem to figure out how to make it work! Please help...
-Scott :confused:

JHL
07-08-2003, 01:23 AM
<form name="MyForm">
<select name="DropField1" onChange="document.MyForm.TextField1.value = this.options[this.selectedIndex].value;">
<option value="">Choose</option>
<option value="Product01">Product01</option>
<option value="Product02">Product02</option>
</select>
<input type="text" name="TextField1">
<br><br>
<select name="DropField2" onChange="document.MyForm.TextField2.value = this.options[this.selectedIndex].value;">
<option value="">Choose</option>
<option value="Product03">Product03</option>
<option value="Product04">Product04</option>
</select>
<input type="text" name="TextField2">
</form>