hakimade
05-12-2014, 12:00 AM
how can i get value from inner iframe page, i have tried the bellow code but not working for me can some one help me out
parent.htm
<!DOCTYPE html>
<html>
<body>
<iframe id="myframe" src="child.htm"></iframe>
<p ></p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
var x = document.getElementById("myframe");
var y = (x.contentWindow || x.contentDocument);
if (y.document)
{
y = y.document;
y.getElementsByTagName("input")[0].value;
alert(y);
}
}
</script>
</body>
</html>
child.htm
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body bgcolor="#000000">
<form action="" method="post" name="myform" id="myform">
<table width="200" border="1">
<tr>
<td width="81" align="left">firstname</td>
<td width="103"><input type="text" name="fname" value="John" id="fname" /></td>
</tr>
<tr>
<td align="left">lastname</td>
<td><input type="text" name="textfield2" value="petter" /></td>
</tr>
</table>
</form>
</body>
</html>
parent.htm
<!DOCTYPE html>
<html>
<body>
<iframe id="myframe" src="child.htm"></iframe>
<p ></p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
var x = document.getElementById("myframe");
var y = (x.contentWindow || x.contentDocument);
if (y.document)
{
y = y.document;
y.getElementsByTagName("input")[0].value;
alert(y);
}
}
</script>
</body>
</html>
child.htm
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body bgcolor="#000000">
<form action="" method="post" name="myform" id="myform">
<table width="200" border="1">
<tr>
<td width="81" align="left">firstname</td>
<td width="103"><input type="text" name="fname" value="John" id="fname" /></td>
</tr>
<tr>
<td align="left">lastname</td>
<td><input type="text" name="textfield2" value="petter" /></td>
</tr>
</table>
</form>
</body>
</html>