Onsubmit功能不起作用
Onsubmit function not working
我的onsubmit函数不工作。
我的PHP文件有两种形式。两个表单标记都有一个onsubmit属性,该属性链接到同一个javascript文件。第一个表单的提交正在工作。第二种形式调用的函数被简化为:
function UserDataCheck()
{
return false;
}
表单标签为
form name='user_form' method='post' onsubmit='return UserDataCheck();'
此标记包含在<>中和双引号,并在PHP文件中进行回显。
请帮忙。这简直把我逼疯了!早些时候,我在UserDataCheck()中进行了一些数据检查,但我去掉了所有这些,看看我是否可以使用onsubmit来阻止用户提交!没有成功。
这里有更多的代码!
echo "<html>";
echo "<head>";
echo "<title>Survey Form</title>";
echo "<link link rel='stylesheet' href='examples.css' type='text/css'>";
echo "</head>";
echo "<script src='validation.js'></script>";
echo "<body topmargin='20', leftmargin='20', rightmargin='20', style='background-color:beige; font-family:calibri;'>";
echo "<img src='CSE Global.jpg' width='250' height='70' align='right' />";
//---------------------------------------------------------------------
// Firstly, we determine who is using this system
// Check $_GET['dex'] for a value, if provided, then it's the user
// if not, then it's the administrator (see my notes below the code for
// more info)
//---------------------------------------------------------------------
"<input type='text' name='dex' length='50'>";
"<input type='boolean' name='sub' length='1'>";
if ($_GET['dex']=="") {
//---------------------------------------------------------------------
// $_GET['dex'] is empty so we can presume this is the Admin
//---------------------------------------------------------------------
echo "<p style='font-family:cambria;font-size:35px;'> WELCOME ADMIN!</p>";
//---------------------------------------------------------------------
// We now check to see if the form has been submitted or not ...
// To do this, we check if the variable 'sub' is in the $_POST array
//---------------------------------------------------------------------
if ($_POST['sub']!=1) {
//---------------------------------------------------------------------
// The form has not been submitted already so present the "admin form"
//---------------------------------------------------------------------
// check that they entered an amount tested, an amount passed,
// and that they didn't pass units than they more than tested
echo "<form name='admin_form' method='post' onsubmit='if(!AdminDataCheck()) return false;'>";
echo "<p><label>Scope of Service <label style='color:red'><strong>*</strong></label> <br/></label> <input type='text' name='scope' length='50' id='ScopeofService' onblur='checkScopeofService()'/><label id='labelScopeofService'></label></p>";
接下来是更多的标签和文本字段。
然后表单标签就关闭了!
echo "<input type='hidden' name='dex' value={$dex}>";
echo "<input type='hidden' name='sub' value=1>";
echo "<input type='SUBMIT' style='background-color:white' name='submit' value='SUBMIT'>";
echo "</form>";
以下是validation.js 中的函数
function AdminDataCheck()
{
var SoS = document.getElementById('ScopeofService').value;
var PNumber = document.getElementById('ProjectNumber').value;
var numericExp = /^[0-9]+$/;
var alphaExp = /^[A-Za-z ]+$/;
var Email = document.getElementById('Email').value;
var emailExp = /^['w'-'.'+]+'@[a-zA-Z0-9'-]+'.[a-zA-z0-9]{2,4}$/;
if (!(SoS.match(alphaExp)))
{
alert("Invalid Scope");
return false;
}
else if(!(PNumber.match(numericExp)))
{
alert("Invalid Project Number.");
return false;
}
else if(!(Email.match(emailExp)))
{
alert("Invalid Email.");
return false;
}
else
{
return true;
}
}
让我强调一下,这几分钟前就开始了,我没有做任何更改,只是重新启动了浏览器和服务器!它停止了工作。这真是令人沮丧!
试试这个:
onsubmit='if(!UserDataCheck()) return false;'
相关文章:
- 使用复杂数组时Jquery自动完成功能不起作用
- 为什么我的流星每个功能都不起作用
- jQuery点击功能在获取请求后不起作用
- 切换功能不起作用
- 为什么不是'我的修剪功能不起作用
- Angular UI Select2指令搜索功能不起作用
- j查询点击功能在手风琴菜单链接上不起作用
- 为什么这个排序功能在 Safari 中不起作用
- 控制器功能在 Angular.js 中不起作用
- AngularJS 路由功能不起作用
- JavaScript更新功能不起作用
- ScriptX 打印功能在 IE8 中不起作用
- JS表单验证功能不起作用
- 本地存储功能中的图像不起作用
- 复选框树视图功能不起作用
- Web音频-AudioParam调度功能不起作用
- 功能的禁用/启用按钮;不起作用
- JavaScript/jQuery:获取选择功能在Firefox和Chrome中不起作用
- 复选框单击功能不起作用
- Ckeditor插件功能在使用setData(“hai”)之后不起作用;