Home » questions » Why does substitution variables not work as part of the document object?

Why does substitution variables not work as part of the document object?

2006-08-05 01:11:51, Category: Programming & Design
How come setting: document.myformName.testname2.value = 'blah blah' will work, but setting the document object using document.formNameString.fieldNameString.value = 'blah blah'; using substitution variables will not work? I really need a way to build the complete document string and have it interpret correctly as: document.variableFormName.variableFieldName.value where variableFormName and variableFieldName are variables. The code I am using is: function echoNameField(){ var formNameString = 'myformName'; var fieldNameString = 'testname'; document.formNameString.fieldNameString.value = 'blah blah'; document.myformName.testname2.value = 'blah blah'; }


Answers

  1. arnobie

    On 2006-08-05 01:35:35


    the document.myformNameString.fieldName will work because it is a form object as but using document.formNameString.fieldName will not work because formName form is not found in the html area... you may right this one... document.+formNameString+.fieldName = 'Blah Blah'; you see that the form name substituted by a variable..