Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery form.submit not working

Tags:

jquery

I have the Code like this which checks code availability if code exists the form does not submit

i have the code which is not working

<script type="text/javascript">
$(document).ready(function() {
    $('#Loading').hide();
            var min_chars = 3;  
            //result texts  
            var characters_error = 'Minimum amount of chars is 3';  
            var checking_html = 'Checking...';      


        $('#reality_form').submit(function(){

            if($('#realitycode').val().length < min_chars){
                $('#Info').html(characters_error);  
            }else{  
                //else show the cheking_text and run the function to check  
                    $('#Info').html(checking_html);  
                        var reltcode = $('#realitycode').val();  

                //use ajax to run the check  
                $.post("http://localhost/Testtt/wp-content/plugins/Realestate Redirection/check_realitycode_availablity.php", { realitycode: reltcode },

                 function(result){  
                    //if the result is 1  
                    if(result == 1){  
                        //show that the username is available
                        alert('hi');  
                        $('#Info').html(reltcode + ' is Available'); 

                    }else{  
                        alert('hello'); 
                        $('#Info').html(reltcode + ' is not Available');

                    } 

                }); 
           return false;    
            }

    });  

 }); 

</script>
<div class="wrap"> 
            <?php    echo "<h2>" . __( 'RealEstate Listing Options', 'oscimp_trdom' ) . "</h2>"; ?>
            <form action="" name="reality" method="post" id="reality_form">
            <input type="hidden" name="reality_hidden" value="Y">  
            Website Url:<input type="text" name="website_url" value="" />
            Listing Code: <input type="text" name="rlt_code" id="realitycode" />
            <input type="submit" name="submit" value="submit" />
            <div id="Info"></div>
            <span id="Loading"><img src="http://localhost/Testtt/wp-content/plugins/Realestate Redirection/loader.gif" alt="" /></span>

            </form>
</div>

As i look on console the Ajax url becomes error but when i use for realitycode keyup() function then Ajax works properly. i want form should not get submit if any error. but form is submitting in every case Please help

like image 731
Ankit Avatar asked Aug 26 '26 17:08

Ankit


1 Answers

Use the .click event instead of submit. Then if the form is valid, call submit yourself in code.

like image 53
Jeff Watkins Avatar answered Sep 01 '26 04:09

Jeff Watkins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!