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

Referencing parent HTML forms from function in child window

Status
Not open for further replies.

woter324

Technical User
Jan 26, 2007
179
GB
Hi All,

Still writing HTA's and learning :).

I have an HTA with a button; when pressed opens a child window using [tt]showModalDialog[/tt]. For the vArgument (MSDN ref), I am passing an instance of the dictionary object from the following function:

Code:
Function collateForm()
	Set oDataDict = CreateObject("Scripting.Dictionary")
	
	[aqua]'Set oForm = document.getElementById("myForm1")[/aqua]
	[aqua]'fN = myForm1.txtFirstName.Value[/aqua]
	[aqua]'lN = myForm1.txtLastName.Value[/aqua]
	
	fN = window.parent.document.getElementById("txtFirstName").value
	lN = window.parent.document.getElementById("txtLastName").value
	
	[aqua]'D1_Val = oForm.txtFirstName.Value[/aqua]
	
	MsgBox fN & " " & lN [aqua]'& " " & D1_Val [/aqua]
	
	oDataDict.Add "firstName", fN [aqua]'"stringA"[/aqua]
	oDataDict.Add "lastName", lN [aqua]'"stingB"[/aqua]
	
	Set collateForm = oDataDict
End Function

Sorry about the commented code. Trying to show my workings.

I am trying to populate the dictionary object with values from text boxes in the parent window. The [tt]MsgBox fN & " " & lN[/tt] shows what I would expect, then I get the error: [tt]Object required: 'window.parent.document.getElementById(...)'[/tt]. The line reportedly in question is [tt]fN = window.parent.document.getElementById("txtFirstName").value[/tt].

It seems to me that once the child form opens, it no longer knows what [tt]myForm1[/tt] is. So the question is, how does one reference a form in the parent window to the child window? I would have thought explicitly telling the child where the form is [tt]fN = window.parent.document.getElementById("txtFirstName").value[/tt] would have done the trick. Clearly not :-(.

My other thought is why does the child form need to know what [tt]fN = window.parent.document.getElementById("txtFirstName").value[/tt]is. Surely it's stored in the dictionary object?

Any pointers suggestions would be greatly apreciated (as always).

BTW, if I comment out the fN & lN and comment in the stringA/B items from [tt]oDataDict[/tt], it appears in the child form as expected.

Many thanks

Woter.
 
[1] collateForm is in the hta
[tt]
Function collateForm()
dim oDataDic,
Set oDataDict = CreateObject("Scripting.Dictionary")
fN = document.getElementById("txtFirstName").value
lN = document.getElementById("txtLastName").value
oDataDict.Add "firstName", fN '"stringA"
oDataDict.Add "lastName", lN '"stingB"
Set collateForm = oDataDict
set oDataDict=nothing
End Function
[/tt]
[2] The modal dialog is open in the hta.
[tt]
dim surl,ret
'surl="xyz.htm" 'your url for the modal dialog
ret=window.ShowModalDialog(surl,collateForm)
[/tt]
[3] The dictionary is retrieved in the dialog page like this.
[tt]
dim x
set x=window.DialogArguments
[/tt]
 
>[self]dim oDataDic,
It is incompletely edited. It should read as follows.
[tt]dim oDataDic,fN,lN[/tt]
It is more or less cosmetic in any case, depending on how you look at it.
 
Thanks again tsuji (you have an excellent habit of saving my bacon!!)

Funny, I had something in the back of my mind about using window.DialogArguments. All the MSDN examples seemed to be using it to get arguments from the child to the parent. Confused me!

Thank you.

Woter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top