• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • Last Modified:

Getting Values From An Iframe In Javascript?

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

0
Blackwave003
Asked:
Blackwave003
1 Solution
 
hieloCommented:
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

0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now