开发者

Ajax Form Validation, JSON code

开发者 https://www.devze.com 2023-03-09 14:41 出处:网络
I have 3 fields in my ajax registration form. Each of them under success has: success: f开发者_C百科unction (j) {

I have 3 fields in my ajax registration form. Each of them under success has:

success: f开发者_C百科unction (j) {
    if (j.ok){
            $(validateEmail.html(j.msg)).attr("id","accept").appendTo($('#loginform') );
    } else {
            $(validateEmail.html(j.msg)).attr("id","invalid").appendTo($('#loginform') );
    }
}

When the field is validated and put in correctly (i.e. password which must have 8 letters HAS 8 letters, the php sends back a JSON message of j.ok = 'true'

Is there a way to under

 $('#register').click(function() {
 //insert code here
    });

to check that all of the j.ok"s are marked as true?

Thanks


As Peter said, don't use valid/invalid as ID. Maybe you want to use classes instead, or jquery's .data().

Then, maybe you can make a counter?

var count = 0;
...
if(j.ok) {
  stuff;
  count = count+1;
}

Then you check:

if(count == 3) {
    allvalid;
}

Regards.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号