-2

I want to disable the my form submit button if user email id already registered .Here is my code for which check email is already registered or not.Now i want to disable the button if email is already registered.My button id is register

$( "#email" ).focusout(function() {

                    var Email= $('#email').val();

                    var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                    var isEmail= regex.test(Email);
                    if(isEmail==true){
                       $.ajax({
                            url: '<?php echo MY_SITE_URL ;?>'+'webapi.php', 
                            type: 'POST',
                            data: { Email : Email , task : 'Customer.checkEmail' },
                            error: function() {  console.log('wrong'); },
                            success: function(res) {

                            if(res==0){
                                    $('.EmailCheck').html('<font style="color:#3CB371;">Checked</font>');
                                    $('#emailcheckflag').val('0');
                                    document.getElementById("demo_ema").innerHTML="";
                                }
                                if(res>0){
                                    $('.EmailCheck').html('<font style="color:#a94442;">Email Address Already Used</font>');
                                    $('#emailcheckflag').val('1');

                                }
                            }
                        });

                    }else{
                        $('.EmailCheck').html('<font style="color:#a94442;">Please check your Email-Id.It is not a valid Email-id.</font>');
                        $('#emailcheckflag').val('1');
                    }
    });
Rob
  • 1,919
  • 3
  • 26
  • 37

1 Answers1

3

Use jquery "prop" with "disabled" attribute

                       if(res==0){
                                $('.EmailCheck').html('<font style="color:#3CB371;">Checked</font>');
                                $('#emailcheckflag').val('0');
                                document.getElementById("demo_ema").innerHTML="";
                                $("#register").prop("disabled",false);
                            }
                            if(res>0){
                                $('.EmailCheck').html('<font style="color:#a94442;">Email Address Already Used</font>');
                                $('#emailcheckflag').val('1');
                                $("#register").prop("disabled",true);
                            }
Stéphane Ammar
  • 1,394
  • 7
  • 16