我有一个表单,它有2个按钮:'提交'和'保存'。提交表单后,根据按钮按下两种单独的功能运行。我想要做的是在按下提交按钮时调用一个函数来检查空字段。我的代码在函数内调用javascript函数
部分:
function valuecheck(){
var msg="";
if($F('entrepreneur_name')==""){
msg+="You need to fill the product name field!\n";
document.getElementById("entrepreneur_name").focus();
}
if($F('address')==""){
msg+="You need to fill in address!\n";
}
if (msg)
{alert(msg);
return false;
}
}
<?php
$chkbutton=$_POST['submit'];
switch ($chkbutton)
{
case "Submit":
// how to call the JavaScript function here..
...//rest of the code
?>
形式:
<input type="submit" style="width:10%" name="submit" value="Save" >
<input type="submit" style="width:10%" name="submit" value="Submit" >
如何调用机箱内的JavaScript函数 “提交”:
在此先感谢。
<form name='myform' method='post' onSubmit="myFunction()">
而在你的js函数:
您不会像这样调用PHP的JavaScript函数,您在**提交表单之前检查字段是否为空**。 – adeneo