faqts : Computers : Programming : Languages : JavaScript : Language Core : Functions

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

23 of 27 people (85%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I set the Form Name and the Field dynamically in a window.opener.document.[FormName].[Field]

Jun 2nd, 2008 17:58
forum net tr, cemal ates, cemal kemal, David Blackledge, Guillermo Cruz, http://www.forumnettr.com


For this specific question, there are arrays defined for exactly this 
purpose:
var formname = "bob";
var fieldname = "fred";
var ref = window.opener.document.forms[formname].elements[fieldname];
However, it is good to know that JavaScript is designed such that ANY 
property can be accessed using a string subscript like so:
var ref = window.opener.document[formname][fieldname]
or a more extreme example:
var ref = 
window["opener"]["document"]["forms"][formname]["elements"][fieldname];
http://www.forumnettr.com
http://www.forumnettr.com/forum