QA.TechInterviews.com - your tech questions answered
Why Does Substitution Variables Not Work As Part Of The Document Object?
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';
}

<form name="myformName">
<input type="text" name="testname" id="id1" value="" onfocus="echoNameField()"><br>
<input type="text" name="testname2" id="id2" value="my value" onBlur="echoNameField()"><br>
<input type="submit" name="submit_name" value="Submit This Now!">
</for
the document.myformNameString.fieldName will work because it is a form object as <form name="myformName"> 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..
the document.myformNameString.fieldName will work because it is a form object as <form name="myformName"> 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..

Back to QA. TechInterviews.com. Powered by Yahoo! Answers and TechInterviews.com community.