recently ,I learn the Jquery to validate data in web. I used c# and B/S . now ,I have create a login form with server control box. like
now I have finish the validate, but the submit button still can work if validate is failed. now I want to set submit disable when validate is failed.
here is my a part of validate code
$(document).ready(function () {
$("#username").blur(function () {
var name = $("#username").val();
if (name == "") {
$("#nameShow").html("*Please input name");
$("#nameShow").addClass("warning");
}
else {
$("#nameShow").html("");
$("#nameShow").removeClass("warning");
}
});
$("#username").click(function () {
//当按钮点击的时候执行下面的代码
//找到页面上id为userName的文本框,并获取文本框内的值,用jquery提供的val方法
var userName = $("#username").val();
$("#nameShow").removeClass("warning");
//判断userName的值是不是为空
if (userName == "") {
//如果为空,提示用户
$("#nameShow").html("*please input your login name.*");
}
else {
$("#nameShow").html("");
}
});
the c# Code:
<asp:Button ID="login_btn" CssClass="btn" runat="server" Text="登录" OnClick="login_btn_Click" />
if validate false, then button cannot to be trigger. I used this way ,but it only work in IE, when switch to google browser ,it still can trigger.
$("#login_btn").submit(function () {
var name = $("#username").val();
var pass = $("#password").val();
var code = $("#verifycode").val();
if (name == "" || pass == "" || code == "") {
return false;
}
else {
return true;
}
});
Can somebody help me with this?