• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 514
  • Last Modified:

Javascript - form field from within an IFrame

how do i get the value of a form field inside a IFrame using JavaScript ?
0
byte1
Asked:
byte1
1 Solution
 
ansudhindraCommented:
With the below code you can..

document.frames["mainContentIFrame"].document.oppInfoForm.testfield.value

where mainContentIFrame is name of the iframe and "oppInfoForm" is form name and "testfield" is the name of the HTML control element.
0
 
darshan_derasariCommented:
Please refer below link to get more help on this.

http://www.dyn-web.com/tutorials/iframes/refs.php


Hope this helps!
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
byte1Author Commented:
ansudhindra: I get this error ...

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; MS-RTC EA 2; OfficeLiveConnector.1.5; OfficeLivePatch.1.3; AskTbARS/5.8.0.12304)
Timestamp: Wed, 1 Sep 2010 14:09:18 UTC


Message: 'document.frames.ifrDynamic.document' is null or not an object
Line: 721
Char: 10
Code: 0



0
 
ansudhindraCommented:
Hi, The above code works fine in IE only. for IE and in other browsers please use

window.top.mainContentIFrame.document.iframeform.innerTextBox.value

mainContentIFrame ==> iFrame name
iframeform ==> form inside iframe
innerTextBox ==> html control element in side iframe form.
0
 
byte1Author Commented:
I am using IE, i tried again but got this error :

alert(document.frames["ifrDynamic"].document.frmCalcAPR.APR.value);

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; MS-RTC EA 2; OfficeLiveConnector.1.5; OfficeLivePatch.1.3; AskTbARS/5.8.0.12304)
Timestamp: Wed, 1 Sep 2010 20:10:14 UTC


Message: 'document.frames.ifrDynamic.document' is null or not an object
Line: 680
Char: 1
Code: 0
URI: http://localhost:47899/IIS/Library/Scripts/ClientSideHelpers.js

0
 
ansudhindraCommented:
you use this code, it works in IE and other browsers

window.top.mainContentIFrame.document.iframeform.innerTextBox.value
0
 
byte1Author Commented:
It  threw up an error too,

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; MS-RTC EA 2; OfficeLiveConnector.1.5; OfficeLivePatch.1.3; AskTbARS/5.8.0.12304)
Timestamp: Wed, 1 Sep 2010 20:14:17 UTC


Message: 'window.top.ifrDynamic.document' is null or not an object
Line: 680
Char: 1
Code: 0
URI: http://localhost:47899/IIS/Library/Scripts/ClientSideHelpers.js

0
 
ansudhindraCommented:
window.top.mainContentIFrame.document.iframeform.innerTextBox.value

mainContentIFrame ==> iFrame name (not id, chek your code once again)
iframeform ==> form inside iframe (not id, chek your code once again)
innerTextBox ==> html control element in side iframe form.  (not id, chek your code once again)

I tested this sample, it is working in IE8, Safari and chrome....
0
 
ansudhindraCommented:
window.top.mainContentIFrame.document.iframeform.innerTextBox.value
 also works for Mozilla firefox and Opera.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now