Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello everyone!

I am using a jQuery plugin for validation of the input boxes, which will shake the boxes if they're left empty when trying to submit them.

Can somebody help me with that? I am using the following code, but it's not working. Please post me the solution or the sample application if you guys know any.

JavaScript
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
    <script src="scripts/jquery.validate.min.js" type="text/javascript"></script>
   <script type="text/javascript">

       $().ready(function () {
           $('#contactform').validate({
               rules: {
                   name: "required",
                   tel: "required",
                   province: "required",
                   email: { required: true
                       //                        email: true
                   }
               },
               messages: {
                   name: "Please enter your Name",
                   tel: "Please enter your Surname",
                   province: "Mobile number is Required",
                   email: {
                       required: "Please enter email",
                       email: "Please enter a valid email address"
                   }
               },
               highlight: function (element, errorClass, validClass) {
                   $(element).stop()
                            .animate({ left: "-10px" }, 100).animate({ left: "10px" }, 100)
                            .animate({ left: "-10px" }, 100).animate({ left: "10px" }, 100)
                            .animate({ left: "0px" }, 100)
                            .addClass(errorClass)
                            .removeClass(validClass);
               },
               unhighlight: function (element, errorClass, validClass) {
                   $(element).stop()
                    .addClass(validClass)
                    .removeClass(errorClass);

               },
               errorPlacement: function (error, element) { }

           });

       });
       
        
    </script>

Thank you
Posted
Updated 7-Mar-11 4:10am
v4
Comments
Manfred Rudolf Bihy 7-Mar-11 10:12am    
Edit: Added pre tags, minor spelling and grammar.
[no name] 7-Mar-11 10:17am    
And what is not working?
shekhardumala 8-Mar-11 3:13am    
the input boxes are not shaking

Here is a working example using the UI effect shake http://blake.breakwatersyndicate.com/2011/03/shaky-validation/[^]


Other than that you are over complicating the implementation a bit, you just need rules and messages. I am not really seeing what you are trying to accomplish with the highlight/unhighlight code. Consider simplifying. You was welcome to build on my code it is released under MIT license like everything else on my site.

Let me know if you run into problems you can find me on twitter @blaketullysmith or just post a comment here or to the article on my blog whichever is easier for you.

Hope that helps.

-Blake
 
Share this answer
 
Comments
shekhardumala 8-Mar-11 3:58am    
Hi,

Thank you for your replay.

I was using your code and it is working fine.
But your code using the following item to shake the form
"$("#contactForm").effect("shake",{ times:4},150);"
But i wants to only shake the input box which error in validating.SO what should i replace to in that line to shake only the input box.

Please suggest.

Thanks a lot.
Blake Tullysmith 16-Mar-11 16:50pm    
In my code if you swap:

$("#shakyvalidation").effect("shake",{ times:4},150);

for:

$(element).effect("shake",{ times:4},150);

that should do what you want.
Hi Guys I used this and achived what i wanted.
&lt;script type="text/javascript" language="javascript"&gt;

$().ready(function () {
$('#showLightDiv').hide();
$('#barcode1Image').hide();
$('#barcode1ImageWrong').hide();

$('#contactForm').validate({
rules: {
name: "required",
tel: "required",
province: "required",
catname: "required",
email: { required:true , email:true },
barcode1: "required",
Terms:"required"

},
messages: {
name: "Please enter your Name",
tel: "Please enter your Surname",
ddlProvince: "Mobile number is Required",
catname: "Cat's name required",
email: "Please enter email",
barcode1: "barcode required",
Terms:"Accept terms and conditions"

},
highlight: function (element, errorClass, validClass) {
$(element).stop()
.removeClass(validClass)
.addClass(errorClass)
.removeClass(validClass)
.css({position: 'relative'})
.css('border-color', 'red')
.animate({ left: -10 },150)
.animate({ left: 0 },150)
.animate({ left: 10 },150)
.animate({ left: 0 },150);
},
unhighlight: function (element, errorClass, validClass) {
$(element).stop()
.removeClass(errorClass)
.addClass(validClass)
.css('border-color', '#d2d2d2');
},
errorPlacement: function(error,element){
}
});
});

&lt;/script&gt;
 
Share this answer
 
we must use css3 and jquery to achieve this task. Textbox validate shake animation in jquery using css3
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900