We help IT Professionals succeed at work.

Getting Values From An Iframe In Javascript?

Blackwave003
Blackwave003 asked
on
Ok, i am trying to do the following:

1) Once the page loads run the email() function
2) Delay getting values from Iframe (since it needs some time to load)
3) Get the "to" text value within the iframe form
4) Update the "to" value on the mainpage with the one from the iframe
5) Submit the form in the iframe


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TEst</title>
<script language="javascript">
function email()
{
document.getElementById('test').src="http://www.example.com/useremail.php?id=34";
setTimeout("getvalues()",5000);
}
 
function getvalues()
{
var to=window.frames['test'].document.forms[0].to.value;
 
}
</script>
</head>
 
<body onload="email();">
 
<form name="mainpage" id="mainpage">
<input type="hidden" name="to" value="" /> 
</form>
 
<iframe id="test" src="about:blank"></iframe>
	
</body>
</html>
 
====================
useremail.php
====================
 
The form in useremail is this
<form method="POST">
<input name="from" size="30" maxlength="35" type="text">
<input name="to" size="30" maxlength="35" type="text">
<input name="subject" size="60" maxlength="105" type="text">
<input type="submit"/>

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Expert of the Year 2008
Top Expert 2008
Commented:
Give the iframe a name. Look at the attached code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>blackWave1.html</title>
<script language="javascript">
function email()
{
document.getElementById('test').src="blackWave2.html";
setTimeout("getvalues()",5000);
}
 
function getvalues()
{
var to=window.frames['test'].document.forms[0].to.value;
 alert(to);
}
</script>
</head>
 
<body onload="email();">
 
<form name="mainpage" id="mainpage">
<input type="hidden" name="to" value="" /> 
</form>
 
<iframe id="test" name="test" src="about:blank"></iframe>
	
</body>
</html>
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>blackWave2.html</title>
</head>
<body>
 
====================
useremail.php
====================
 
The form in useremail is this
<form method="POST">
<input name="from" size="30" maxlength="35" type="text">
<input name="to" size="30" maxlength="35" type="text" value="hi">
<input name="subject" size="60" maxlength="105" type="text">
<input type="submit"/>
 
</body>
</html>

Open in new window

Forced accept.

Computer101
EE Admin

Explore More ContentExplore courses, solutions, and other research materials related to this topic.