Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
单击调用Submit javascript函数上的HTML表单的侦听器上的HTML按钮_Javascript_Php_Html - Fatal编程技术网

单击调用Submit javascript函数上的HTML表单的侦听器上的HTML按钮

单击调用Submit javascript函数上的HTML表单的侦听器上的HTML按钮,javascript,php,html,Javascript,Php,Html,我是web开发的新手,我创建了一个简单的html页面。该页面有两个按钮,提交和显示数据。提交按钮用于在验证表单后将表单数据发布到特定页面。这个按钮很好用。“显示数据”按钮出现问题。按钮应该打开一个单独的页面,不应该有任何形式的验证。页面正在打开,但表单也正在验证 html页面: <html> <head> <script> function validateForm() { var name=document.forms["myForm"]["name"].v

我是web开发的新手,我创建了一个简单的html页面。该页面有两个按钮,提交显示数据提交按钮用于在验证表单后将表单数据发布到特定页面。这个按钮很好用。“显示数据”按钮出现问题。按钮应该打开一个单独的页面,不应该有任何形式的验证。页面正在打开,但表单也正在验证

html页面

<html>
<head>
<script>
function validateForm()
{
var name=document.forms["myForm"]["name"].value;
var email=document.forms["myForm"]["email"].value;
var mobile=document.forms["myForm"]["mobile"].value;
var address=document.forms["myForm"]["address"].value;
var atpos=email.indexOf("@");
var dotpos=email.lastIndexOf(".");
if (name==null || name=="")
  {
  alert("Name must be filled out");
  return false;
  }

else if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length)
  {
  alert("Not a valid e-mail address");
  return false;
  }

  else if(isNaN(mobile)||mobile.indexOf(" ")!=-1)
  {
  alert("Enter numeric value")
  return false; 
  }
  else if (mobile.length != 10)
  {
  alert("Enter 10 digit mobile");
  return false;
  }
  else if (mobile.charAt(0)=="0")
  {
  alert("Mobile no should not start with 0");
  return false;
  }
  else if (address==null || address=="")
  {
  alert("Address must be filled out");
  return false;
  }

}
</script>

</head>

<body>
<h2>Employee Details Entry</h2>
<form name="myForm" action="insertDisplay.php" onSubmit="return validateForm()" method="post">
Name: <input type="text" name="name"><br/>
Email: <input type="text" name="email"><br/>
Mobile: <input type="text" name="mobile"><br/>
Address: <input type="text" name="address"><br/>
<input type="submit" value="Submit"> <button onClick="location.href = 'insertDisplay.php'">Display Data</button>
</form>

</body>

</html>

函数validateForm()
{
var name=document.forms[“myForm”][“name”].value;
var email=document.forms[“myForm”][“email”].value;
var mobile=document.forms[“myForm”][“mobile”].value;
var address=document.forms[“myForm”][“address”].value;
var atpos=email.indexOf(“@”);
var dotpos=email.lastIndexOf(“.”);
如果(名称==null | |名称==“”)
{
警告(“必须填写姓名”);
返回false;
}
否则,如果(在位置处

显示数据
此行不在表单中…

为此按钮指定您想要的类型

<button type="button" onClick="location.href = 'insertDisplay.php'">Display Data</button>
显示数据

您可以从表单中取出值,也可以使用,
标记。它不会提交您的表单,并将按照您的预期工作

<input type="button" value="display data" onClick="location.href = 'a.php'">

我想您也希望在单击按钮后将数据传递到PHP文件? 如果您将表单推出,则不会发送表单,并且您将没有数据。 事实上,您希望两个按钮都提交表单,但只有第一个按钮应该验证表单

如果是这样,您可以这样做:


名称:
电子邮件:
手机:
地址:
您可以在insert.php文件上通过检查$\u POST['typesubmit']值来区分显示和提交

如果希望“显示”按钮将表单发布到另一个php文件上,可以执行以下操作:

<form name="myForm" action="insert.php" method="post">
Name: <input type="text" name="name"><br/>
Email: <input type="text" name="email"><br/>
Mobile: <input type="text" name="mobile"><br/>
Address: <input type="text" name="address"><br/>
<input type="submit" value="Submit" onclick="return validateForm();" />
<input type="submit" value="Display Data" onclick="document.myForm.action='display.php';" />
</form>

名称:
电子邮件:
手机:
地址:

这是因为您没有关闭submit按钮的输入标签,但按钮在submit按钮下方。我希望按钮并排放置。。。。。。。。。。
<form name="myForm" action="insert.php" method="post">
Name: <input type="text" name="name"><br/>
Email: <input type="text" name="email"><br/>
Mobile: <input type="text" name="mobile"><br/>
Address: <input type="text" name="address"><br/>
<input type="submit" value="Submit" onclick="return validateForm();" />
<input type="submit" value="Display Data" onclick="document.myForm.action='display.php';" />
</form>