表单上的隐形提交按钮
invisbile submit button on form
>我有一个受验证代码约束的表单。例如,用户名必须包含字母字符。因此返回真或假。
function isAlphapet()
{
var alphaExp = /^[a-zA-Z]+$/;
var namee=document.validation.userName.value;
var nalt=document.getElementById('name1');
if(namee!="")
{
if(!namee.match(alphaExp))
{
nalt.innerHTML="<font color='red'> Invalid Name: " + document.validation.userName.value + "</font>";
document.validation.userName.focus();
document.validation.userName.value="";
//This will remove the success class if the user tries to modify it incorrectly.
document.getElementById("userName").className = document.getElementById("userName").className.replace(" validationSuccess", "");
//This is calling the css class name validationError to color the text box border in red if there is an error.
//Leaving the replacing attribute empty incase the user hasn't input the correct string.
document.getElementById("userName").className = document.getElementById("userName").className + " validationError";
return false;
}else{//if it's validated correctly
nalt.innerHTML="";
//The text box should be green.
document.getElementById("userName").className = document.getElementById("userName").className + " validationSuccess";
return true;
}
}
else if(namee.length==0) { //if the user leaves it blank.
nalt.innerHTML="<font color='red'> Enter Name</font>";
document.getElementById('name1').focus();
document.getElementById("userName").className = document.getElementById("userName").className.replace(" validationSuccess", "");
document.getElementById("userName").className = document.getElementById("userName").className + " validationError";
//The above is explained on line 27+.
return false;
}
}
在用户名文本框的表单中,我有:
Your Name:<br /><input name="userName" id="userName" onBlur="isAlphapet()" type="text" size="20" maxlength="25" /><br />
一旦上述返回 true,我需要启用我的按钮。但是出于某种原因,当我尝试在体内的 JScript 中使用它时,Alphapet 没有返回任何内容。
有人有解决方案吗?
非常感谢。
编辑:
谢谢你回复斯里尼。
嗯,不,在我进行更改后,整个验证功能停止工作。我想要实现的目标比听起来简单一些。我需要一个 if 语句或类似以下内容的内容:
if (isAlphapet()== true && emailvalid()== true && browserValid()==true){
document.validation.sumb.disabled=false;
}
else{
document.validation.subm.diabled=true;
}
其中验证是我的表单的名称。我试图在标题和正文中使用它。它也无法识别我的函数的返回值。但是按钮禁用和启用仅在/form 标签之后有效
试试这个
<html>
<head>
<script type="text/javascript">
function isAlphapet()
{
var alphaExp = /^[a-zA-Z]+$/;
var namee=document.getElementById('userName').value;
var nalt=document.getElementById('name1');
if(namee!="")
{
if(!namee.match(alphaExp))
{
alert(namee);
nalt.innerHTML="<span style='color:red;'> Invalid Name: " + namee + "</span>";
document.validation.userName.focus();
document.validation.userName.value="";
//This will remove the success class if the user tries to modify it incorrectly.
document.getElementById("userName").className = document.getElementById("userName").className.replace(" validationSuccess", "");
//This is calling the css class name validationError to color the text box border in red if there is an error.
//Leaving the replacing attribute empty incase the user hasn't input the correct string.
document.getElementById("userName").className = document.getElementById("userName").className + " validationError";
return false;
}
else{//if it's validated correctly
nalt.innerHTML="";
//The text box should be green.
document.getElementById("userName").className = document.getElementById("userName").className + " validationSuccess";
return true;
}
}
else if(namee.length==0) { //if the user leaves it blank.
nalt.innerHTML="<font color='red'> Enter Name</font>";
document.getElementById('name1').focus();
document.getElementById("userName").className = document.getElementById("userName").className.replace(" validationSuccess", "");
document.getElementById("userName").className = document.getElementById("userName").className + " validationError";
//The above is explained on line 27+.
return false;
}
}
</script>
</head>
<body>
<div style="float:left">
<form>
Your Name:<br /><input name="userName" id="userName" onBlur="isAlphapet()" type="text" size="20" maxlength= "25" /><br />
</form>
</div>
<div id="name1" style="float:left"></div>
</body>
</html>
相关文章:
- 带有验证和隐藏字段值的提交按钮
- 如何在 API 调用后和 if 语句中启用提交按钮
- 提交按钮,该按钮位于使用 Excel VBA 的 Javascript 中
- 如何使用提交按钮搜索表中的记录
- 在单击按钮前后禁用提交按钮
- 在表单完成并确认密码之前,请禁用提交按钮
- 如何使用Java脚本创建提交按钮's的拖放功能
- 如何在单击“提交”按钮时为“新建”窗口编写JavaScript,用“确定”和“取消”显示注册信息
- 提交按钮通过JQuery和JavaScript函数所做的更改不会持续
- 从输入时提交到jQuery,无需提交按钮,无需表单操作
- onclick提交按钮JSP
- 通过提交按钮传递值
- 如果ng单击附加到提交按钮,则表单未验证
- 如何在Razor MVC 5.2.3 Ajax中使用多个提交按钮
- 使用提交按钮隐藏未选中的单选按钮
- Ruby/JS如何在提交按钮后重新加载页面
- JavaScript表单提交没有't fire asp服务器端点击功能的提交按钮
- 使用javascript后,提交按钮不起作用
- 如何使用jQuery/Ajax响应特定的提交按钮
- 表单中的提交按钮在 PHP 打印中不起作用