Solved

Javascript - form field from within an IFrame

Posted on 2010-08-31
10
461 Views
Last Modified: 2012-05-10
how do i get the value of a form field inside a IFrame using JavaScript ?
0
Comment
Question by:byte1
10 Comments
 
LVL 4

Expert Comment

by:dschauhan82
ID: 33573710
0
 
LVL 13

Expert Comment

by:ansudhindra
ID: 33573720
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
 
LVL 5

Expert Comment

by:darshan_derasari
ID: 33573826
Please refer below link to get more help on this.

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


Hope this helps!
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:byte1
ID: 33577177
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
 
LVL 13

Expert Comment

by:ansudhindra
ID: 33580837
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
 

Author Comment

by:byte1
ID: 33580872
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
 
LVL 13

Expert Comment

by:ansudhindra
ID: 33580896
you use this code, it works in IE and other browsers

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

Author Comment

by:byte1
ID: 33580917
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
 
LVL 13

Accepted Solution

by:
ansudhindra earned 500 total points
ID: 33580954
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
 
LVL 13

Expert Comment

by:ansudhindra
ID: 33583903
window.top.mainContentIFrame.document.iframeform.innerTextBox.value
 also works for Mozilla firefox and Opera.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question