First you need to abandon the habit of addressing forms by the name; the attribute is deprecated except for the elements of forms.
The neatest way might be to use a function to address the desired element, by passing it the ID (not name) of its form, the name of the element and the value:
Code:
<form id='f1'>
<input name='inp1' type=text>
</form>
<script type='text/javascript'>
function writeFormElem( formID, elemName, elemValue )
{
var formRef = document.getElementById( formID );
if( formRef && formRef.nodeName == 'FORM' && formRef.id == formID )
formRef[ elemName ].value = elemValue;
else
alert( 'Invalid form ID:"' + formID + '"' );
}
writeFormElem( 'f1', 'inp1', 'OK' );
</script>
Bookmarks