Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Javascript - form field from within an IFrame

Posted on 2010-08-31
10
462 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Page auto-refreshes when scrolled on iPhone. 5 55
Do alert on select 6 14
send email part1 9 28
How to filter by key press ? 6 23
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…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

828 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