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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOM concat variable into instruction 2

Status
Not open for further replies.

chetFinster

Programmer
Joined
Mar 3, 2005
Messages
6
Location
US
See below - "B" works, while "A' doesn't.

I want to allow the user to change some values in the FORM by passing params in a function. The value of 'thisFormName' is retrieved dynamically so the script is re-useable (test for FORM type).

Simply trying to use the variable (thisFormName) to allow execution of a command based on a retreived value to change a value in a FORM, but the 'A' version doesn't execute.

A. eval("document." + thisFormName + ".elements[0].style.width=" + newWidth);

B. document.form2.elements[0].style.width= newWidth;

Your help is appreciated after MUCH digging and hair pulling.
 
Try using the forms collection:
Code:
document.forms[thisFormName].elements[0].style.width=newWidth;


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 

And you should ALWAYS append a unit specifier, otherwise you'll find it probably won't work in Firefox:

Code:
document.forms[thisFormName].elements[0].style.width = newWidth + 'px';

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 
Good catch on that one BRPS!


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top