Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic form element names in function

Status
Not open for further replies.

dragonturtle

Programmer
Sep 25, 2003
55
CA
Hi,

I have a form in page that looks something like this:

Code:
<form name=myForm>
<input type=text name=value1 onBlur=calculateForm(1)>
<input type=text name=result1>
<input type=text name=value2 onBlur=calculateForm(2)>
<input type=text name=result2>
<input type=text name=value3 onBlur=calculateForm(3)>
<input type=text name=result3>
</form>

The calculateForm() function needs to take the parameter and append it to the name of the field, but I can't figure out how to do it.

Code:
function calculateForm(num)
{
  var d = document.myForm;
  d.result+num.value = d.value+per.value;
}

Any help is appreciated. Thanks.
 
Woohoo! Figured it out! It worked like this:

Code:
function calculateForm(num)
{
  var d = document.myForm;
  d[&quot;result&quot;+num].value = d[&quot;value&quot;+num].value;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top