Solved

Javascript - form field from within an IFrame

Posted on 2010-08-31
10
456 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
 

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now