在弹出窗口中显示表单结果

时间:2019-06-25 09:26:54

标签: javascript

如何在弹出的window.open中显示名字和电子邮件的结果。 例子:

恭喜!

名称:

发送电子邮件:

function validateForm()
    {
        var ufname=document.forms["regform"]["fname"].value;
        var uemail=document.forms["regform"]["email"].value;
        if (ufname=="" || uemail=="")
        {
            alert("PLEASE ENTER THE VALUES!");
            return false;
        }
    }
<form method="post" name="regform" id="regform" onsubmit="return validateForm()">
  <label>First name </label>
  <input  type="text" name="fname" id="fname" placeholder="Your Name">
  <label>Email Address </label>
  <input  type="text" name="email" id="email" placeholder="hi@domain.com">
  <button type="submit" value="submit">Register</button>  <input type="reset" value="Reset">
</form>

2 个答案:

答案 0 :(得分:0)

尝试

 function validateForm()
    {
        var ufname=document.forms["regform"]["fname"].value;
        var uemail=document.forms["regform"]["email"].value;
        if (ufname=="" || uemail=="")
        {
            alert("PLEASE ENTER THE VALUES!");
            return false;
        } else {
           var popupWindow = window.open('');
           popupWindow.document.body.innerHTML = '<div>Your Name: '+ufname+'</div><div>Your Email: '+uemail+'</div>'
        }
    }

答案 1 :(得分:0)

如果要使用新窗口,请尝试使用window.open

function validateForm()
    {
        var ufname=document.forms["regform"]["fname"].value;
        var uemail=document.forms["regform"]["email"].value;
        if (ufname=="" || uemail=="")
        {
            alert("PLEASE ENTER THE VALUES!");
            return false;
        }
        else
        {
            var myWindow = window.open("", "RegisterWindow", "width=200,height=100");
            myWindow.document.write("<p>Congratulations! </p> <p>Name :  "+ufname+".</p><p>EMail : "+ uemail +".");
        }
    }
<form method="post" name="regform" id="regform" onsubmit="return validateForm()">
  <label>First name </label>
  <input  type="text" name="fname" id="fname" placeholder="Your Name">
  <label>Email Address </label>
  <input  type="text" name="email" id="email" placeholder="hi@domain.com">
  <button type="submit" value="submit">Register</button>  <input type="reset" value="Reset">
</form>