Home  >  Article  >  Web Front-end  >  How to implement JS to pass value to form in iframe

How to implement JS to pass value to form in iframe

黄舟
黄舟Original
2017-03-25 14:44:461513browse

This article mainly introduces the method of JS to transfer values ​​​​to forms in iframes, involving js related implementation techniques for page elements and form attribute operations. Friends in need can refer to the following

The examples in this article describe JS Implement the method of passing values ​​to the form in the iframe. Share it with everyone for your reference, the details are as follows:

Add the contentWindow attribute to the iframe before assigning the value. Test everything in IE and firefox and everything is ok.

For example:

Page a .jsp

<script language="Javascript">
function ExecuteSql()
{
var FormObj = document.getElementById("ResultShowFrame").contentWindow;
var SqlStr=document.getElementById("sqlcontent").value;
if (SqlStr !="")
{
  FormObj.document.getElementById("Sql").value=SqlStr;
  FormObj.document.getElementById("Result").value=&#39;Submit&#39;;
  FormObj.document.ExecuteForm.submit();
}
}
</script>
<form name="dbcompress" action="?Action=CompressDate" method="post">
<textarea name="sqlcontent" rows="3" wrap="OFF" style="width:100%;" id="sqlcontent"></textarea>
<input name="Submit" type="button" onClick="ExecuteSql();" class="Anbut2"  value=" 执 行 ">
</form>
<iframe id="ResultShowFrame" scrolling="yes" src="b.asp" style="width:100%;height:420;" frameborder=1></iframe>

Page b.jsp:

<form name="ExecuteForm" method="post" action="">
  <input type="hidden" name="Sql" id="Sql">
  <input type="hidden" name="Result" id="Result">
</form>

The above is the detailed content of How to implement JS to pass value to form in iframe. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn