如何将表单输入传递到javascript iframe URL?
可能重复:如何将表单输入传递到javascript iframe URL?,javascript,jquery,iframe,webforms,argument-passing,Javascript,Jquery,Iframe,Webforms,Argument Passing,可能重复: 我有一个表单,我想让它做两件事——用一个按钮提交一个标准表单请求(可以正常工作),还有一个按钮(也可以部分正常工作)在页面内打开一个iframe,表单中的值附加到iframe URL 以下是我使用的脚本: <script language="JavaScript" type="text/javascript"> function makeFrame() { ifrm = document.createElement("IFRAME"); ifrm.setAttri
我有一个表单,我想让它做两件事——用一个按钮提交一个标准表单请求(可以正常工作),还有一个按钮(也可以部分正常工作)在页面内打开一个iframe,表单中的值附加到iframe URL 以下是我使用的脚本:
<script language="JavaScript" type="text/javascript">
function makeFrame() {
ifrm = document.createElement("IFRAME");
ifrm.setAttribute("src", "https://www.hostname.com/filepath");
ifrm.style.width = 340+"px";
ifrm.style.height = 630+"px";
document.body.appendChild(ifrm);
}
</script>
函数makeFrame(){
ifrm=document.createElement(“IFRAME”);
ifrm.setAttribute(“src”https://www.hostname.com/filepath");
ifrm.style.width=340+“px”;
ifrm.style.height=630+“px”;
文件.body.appendChild(ifrm);
}
及表格:
<FORM action="https://www.hostname.com/filepath" method="POST" name="form" id="viewGift">
<P><br>
<LABEL for="giftId">giftId: </LABEL><INPUT type="text" name="giftId"><BR>
<INPUT type="radio" name="opt1" value="1" checked> opt1<BR>
<INPUT type="radio" name="opt2" value="2"> opt2<BR>
<INPUT type="radio" name="opt3" value="3"> opt3<BR>
<INPUT type="radio" name="opt4" value="4"> opt4<BR>
<INPUT type="button" value="Send Gift" onclick="formSubmit()">
<INPUT type="button" value="Show Gift" onclick="makeFrame()">
</P>
</FORM>
吉夫蒂德:
opt1
opt2
opt3
opt4
我的表单提交正确,但我不知道如何让它通过showgift按钮将表单giftId值传递给iframeURL。如果我硬编码URL,“显示礼物”按钮工作得很好,但这对页面的用途没有多大帮助
基本上,我需要Show Gift按钮来创建一个带有URL的iframe,用户在其中输入giftId。这应该可以:
function makeFrame() {
var ifrm = document.createElement("IFRAME");
var gift_id=document.getElementById('viewGift').elements['giftId'].value
ifrm.setAttribute("src", "https://www.hostname.com/filepath/"+gift_id);
ifrm.style.width = 340 + "px";
ifrm.style.height = 630 + "px";
document.body.appendChild(ifrm);
}
谢谢我不得不稍微调整一下,Chrome希望最后的}与document.body行在同一行。现在我只想知道如何将iframe嵌入到一个表中,而不是将它附加到正文的末尾:-)转到Google!