Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript - form field from within an IFrame

Posted on 2010-08-31
10
Medium Priority
?
486 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
[X]
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
10 Comments
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 2000 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

636 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