将表单提交到另一个页面(与ACTION中使用的页面不同) [英] Submit form to another page (which is different from the page used in ACTION)
问题描述
我有这样的表单:
index.php
< form method =postaction =send.php>
< input type =submitvalue =Send/>
< / form>
所以,如果我在textarea中输入一些内容并点击Send,它会被提交给send .php页面。但我想包含另一个按钮来预览它。也就是说,当点击这个按钮时,上面的表单被提交到preview.php,它将在一个新的空白窗口/标签页中打开(原始页面即index.php将保持原样)。这是显示消息的预览,用户将发送。
我不知道该怎么做。
>< form method =postaction =send.phpid =idOfForm>
< input type =submitvalue =Send/>
< / form>
< button onclick =doPreview();>预览< / button>
< script type =text / javascript>
函数doPreview()
{
form = document.getElementById('idOfForm');
form.target ='_ blank';
form.action ='preview.php';
form.submit();
form.action ='send.php';
form.target ='';
}
< / script>
I have a form like this:
index.php
<form method="post" action="send.php">
<textarea name="msg" id="msg"></textarea>
<input type="submit" value="Send" />
</form>
So, if I enter something in textarea and clicked on "Send", it is submitted to "send.php" page. But I want to include another button for previewing it. That is, when this button is clicked, the above form is submitted to "preview.php" which will be opened in a new blank window/tab (original page ie. index.php will be there intact). This is to display a preview of the message, that the user is going to send.
I do not know how to do this.
Use Javascript to temporarily change the action and target:
<form method="post" action="send.php" id="idOfForm">
<textarea name="msg" id="msg"></textarea>
<input type="submit" value="Send" />
</form>
<button onclick="doPreview();">Preview</button>
<script type="text/javascript">
function doPreview()
{
form=document.getElementById('idOfForm');
form.target='_blank';
form.action='preview.php';
form.submit();
form.action='send.php';
form.target='';
}
</script>
这篇关于将表单提交到另一个页面(与ACTION中使用的页面不同)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!