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!

Iframe needs parent forms variables 1

Status
Not open for further replies.

ntm0n

Programmer
Jun 22, 2001
30
US
I have tried to access the parent form object values without success. I have tried:

var = parent.document.formname.taDescription.value

and it does not return a value. Is it possible in VBS or ASP to obtain these values from an iframe?

G.
 
Try:

var = window.parent.document.formname.taDescription.value "did you just say Minkey?, yes that's what I said."

MrGreed
 
MrGreed,

Thanks for the try, but that does not work either. I've tried about every variation of window, parent, top etc... that I can think of...

G.
 
ok here is test code for you..

This works:

---------- This is the Main html code page ----------------------

<HTML>
<HEAD>
</HEAD>
<BODY>
<IFRAME ID=Test src=&quot;c:\SupTest.htm&quot; width=200 height=200>
</IFRAME>
<BR>
<BR>
<FORM ID=FormTest>
<input ID=frmTxtText type=text value=&quot;&quot;>
</FORM>
</BODY>
</HTML>
------------------------------------------------------------


---------- This is the page code that loads in the iframe ------
<HTML>
<HEAD>
<script language=vbscript>
function TestIt()
dim d
d=window.parent.document.forms(0).frmTxtText.value
msgbox d
end function
</script>
</HEAD>
<BODY>
<BR>
<BR>
<FORM ID=FormTest2>
<input ID=frmbut type=button value=&quot;test&quot; onclick='TestIt()'>
</FORM>
</BODY>
</HTML>
------------------------------------------------------------

Just create these 2 html files to see how it works.

The code you really want is vbscript:

function TestIt()
dim d
d=window.parent.document.forms(0).frmTxtText.value
msgbox d
end function

The javascript would look like (works in IE and Netscape6.0^:

function TestIt(){
var d=window.parent.document.getElementById(&quot;frmTxtText&quot;).value
alert(d);
} &quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
MrGreed - you are no doubt a genius! Thanks - have it working....

G.
 
MrGreed,

Just one more question if I may...

Using the VBScript example, how can you access the variable 'd' in asp after the function was called?

I thought that vbscript was part of asp, so it seems to me that the variable 'd' should be available inside an asp tag..

does this make sense...

In other words, if I do:

<script language=vbscript>
dim d
d=window.parent.document.forms(0).frmTxtText.value
</script>

<%=d%>

why isn't the variable 'd' available in side a asp tag? Dont vbscript variables reside within or aren't they made available to asp? (I was assuming since you can use vbscript within asp tags that this was possible, however using the d=window.parent.document.forms(0).frmTxtText.value
inside of asp does not work).

Thanks for all your help!

G.

 
VBScript is the language used by ASP, but when VBScript is on the client side (between script tags), an ASP page cannot access the client side variables or functions.

If you want to be able to access the variable &quot;d&quot;. Then you would have to set a hidden field on a form and place the value &quot;d&quot; in it then when you &quot;run&quot; your ASP page it can grab the value from the hidden form field. <-- that is the only way I know of how to grab the variable other than explicitly passing the &quot;d&quot; variable(value) in the url to the ASP page. &quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top