javascriptjquery-validateerrorplacement

errorplacement not allowing jquery validate to work


This is my first time using javascript in a website. I have very low understanding of the language and rely very much on tutorials and reading through other people's questions/solutions.

I have a HTML form that I formatted using a table format. I happen to have some radio buttons in the form too and what happens is once I include errorPlacement in the javascript code, validation for the form doesn't happen. I need for the error message not to disrupt the text of my radio buttons, hopefully appearing on top before the options or after.

If I take out the errorPlacement codes, validation ('this field is required' messages appear at the default location) works as per normal.

Please have a look at my code and let me know if I'm missing anything. I have a feeling it's something simple like a comma or bracket and I have tried a few workarounds but nothing seemed to work.

<script type="text/javascript">
    $(document).ready(function(){
        $("#quoteform").validate({
            errorPlacement: function(error, element) {
                 error.insertBefore(element);   
             },          
        }),
    })                        
</script>

Solution

  • you had a few syntax errors - should be

    $(document).ready(function () {
        $("#quoteform").validate({
            errorPlacement: function (error, element) {
                error.insertBefore(element);
            }
        });
    })