将表单数据提交到弹出窗口并打印该弹出窗口

时间:2014-06-23 18:17:19

标签: javascript html

我正在使用此代码从表单

获取提交的数据
<input id="name" name="name" type="text" class="auto-style8" style="width: 70%" />
<button id="singlebutton" name="singlebutton" class="btn btn-primary" onclick="return submit();">Submit</button> 
<div id="info"></div>
<script type="text/javascript">
    function submit()
    {
        var name = document.getElementById("name").value;
        document.getElementById("info").innerHTML = " My Name is "+name+" ";
    return false;
    }
</script>

结果显示在与窗体相同的窗口中。 我想在弹出窗口中显示输出,并能够链接主窗口中的打印按钮,一旦点击将打印该弹出窗口的内容

edit: just to clarify more.

form submitted > open a new window > displays the entered results

感谢

2 个答案:

答案 0 :(得分:0)

您可以这样修改代码:

<input id="name" name="name" type="text" class="auto-style8" style="width: 70%" />
<button id="singlebutton" name="singlebutton" class="btn btn-primary" onclick="return submit();">Submit</button> 
<div id="info"></div>
<script type="text/javascript">
    function submit()
    {
        var name = document.getElementById("name").value;
        document.getElementById("info").innerHTML = " My Name is "+name+" ";
        var r = window.confirm(" My Name is "+name+" .Click Ok To Print");
        if (r == true) {
            x = window.print();
        }
    return false;
    }
</script>

希望这符合您的目的。

答案 1 :(得分:0)

我想你想要像

这样的东西
<input id="name" name="name" type="text" class="auto-style8" style="width: 70%" />
<button id="singlebutton" name="singlebutton" class="btn btn-primary" onclick="return submit();">Submit</button> 
<div id="info"></div>
<script type="text/javascript">
    function submit()
    {
        var name = document.getElementById("name").value;
        var output = " My Name is "+name+" ";
        var myWindow = window.open("data:text/html," + encodeURIComponent(output),
                   "_blank", "width=200,height=100");

        x = window.print();

        return false;
    }
</script>

我使用this作为灵感:)