errorplacement not allowing jquery validate to work

1.2k views Asked by At

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>
2

There are 2 answers

1
politus On BEST ANSWER

you had a few syntax errors - should be

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

error is a string. So error.insertBefore doesn't make sense. Try $("<div>").insertBefore (element).text (error)