Reputation: 1
I am having an html page consisting of an iframe:
<html>
<body>
<iframe id = "i1" name = "i1" src = "C:\Documents and Settings\adivekar\Desktop\sa.html"></iframe>
<br><input type = "text" name = "t1" id = "One"/>
<br><input type = "button" value = "change1" name = "b1" onclick = "call1()">
<script type = "text/javascript">
function call1(){
var a = document.getElementById('i1');
var b = a.contentDocument;
b.open()
var c = b.getElementById('Two');
c.value = "dfsdf";
}
</script>
</body>
The page containing iframe is:
<html>
<body>
<input type = "text" name = "t2" id = "Two"/>
</body>
</html>
I am unable to update the value of textbox in the iframe.
Upvotes: 0
Views: 1395
Reputation: 324477
If the iframe doesn't come from the same domain as the main document, you will not be able to access the iframe's document. If it does, your code should work in most browsers. I'd change it slightly for browsers that don't support the contentDocument
property of ifame elements, and remove the call to the iframe document's open()
method, which is unnecessary and possibly problematic:
function call1(){
var a = document.getElementById('i1');
var b = a.contentDocument || a.contentWindow.document;
var c = b.getElementById('Two');
c.value = "dfsdf";
}
Upvotes: 2
Reputation: 17752
Try
document.getElementById('i1').getElementById('Two').value = "..";
Upvotes: 0