setting value to a form in iframe and submit the form.
window.frames['equityIFrame'].document.forms[0].[actionParam] = "equityAction";
window.frames['equityIFrame'].document.forms[0].submit();
This code works fine in IE and other browser.
In Edge browser, throws the below error.
cannot read the property 'forms' of undefined.
What will be the work around for this.
You can use HTMLIFrameElement.contentWindow to access the iframe's document and its internal DOM. You can refer to my sample code below, it works well in Edge and other browsers:
iframe.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<iframe src="form.html" id="test"></iframe>
<input type="button" value="click" onclick="ChangeIframe()" />
<script>
function ChangeIframe() {
document.getElementById("test").contentWindow.document.getElementById("fname").value = "myname";
document.getElementById("test").contentWindow.document.forms[0].submit();
}
</script>
</body>
</html>
form.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form action="index.html" method="get">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>