I want to throw an error message if user doesn't input any value for a particular field. I am using blur event. I don't want to use ALERT function for throwing error messages. What are the other options we have available in jquery for error handling?
A:
It sounds like you're looking for form validation, for which there's a jQuery plugin.
Jamie Ide
2010-03-11 18:05:41
That's a wrong link. I am already using validation plugin , but for custom field, I have added a custom method which I am extending for checking blank values.
yogsma
2010-03-11 18:09:11
I fixed the link. You can do custom validation with the plugin: http://docs.jquery.com/Plugins/Validation/Validator/addMethod
Jamie Ide
2010-03-11 18:15:29
+1
A:
Since you're validating a form, I'd strongly suggest you use the jQuery Validate plugin. It is widely used by major sites and is very user-friendly - for example, doesn't show any form errors until they've tried to submit the form, in case they were coming back to fill something in, but after that gives immediate feedback when the field is correct.
What that plugin does to display errors is append them to the page itself. For your own error handling, you can leave placeholder elements on the page, then place messages in them and show()
or hide()
them as necessary.
Nathan Long
2010-03-11 18:06:52