~ overflow ~

Tag: form

jQuery validator special highlights for radio and checkbox

by z3n on Jun.17, 2010, under Coding, Tips & Hints

Problem:

Highlighting a checkbox or radio button on error with jquery’s validator plugin is not a good idea, specially if you’re adding borders , backgrounds or something like, since it’s NOT supported over all browsers. I have a little bar around them that goes red if something is wrong, however, it’s not possible to add it if there’s many elements, so it’s better add a wrapper element and style it, in my case i added an element which ID is the same of input NAME, a little change on the plugin make things automatic.

Solution:

		highlight: function( element, errorClass, validClass ) {
			$(element).addClass(errorClass).removeClass(validClass);
			if (($(element).attr("type") == "radio" || $(element).attr("type") == "checkbox") && $("#"+$(element).attr("name")).length > 0)
				$("#"+$(element).attr("name")).addClass(errorClass).removeClass(validClass);
		},
		unhighlight: function( element, errorClass, validClass ) {
			$(element).removeClass(errorClass).addClass(validClass);
			if (($(element).attr("type") == "radio" || $(element).attr("type") == "checkbox") && $("#"+$(element).attr("name")).length > 0)
				$("#"+$(element).attr("name")).removeClass(errorClass).addClass(validClass);
		}
Leave a Comment :, , , , more...

little jQuery to loop through checkboxes

by z3n on Aug.18, 2009, under Coding

This is a little function to loop throught a specific form or id with checkboxes, it will check if the checkbox is checked and then you can `do something`.

  1. function (what)
  2. {
  3. jQuery.each(jQuery("#"+what+" :checkbox"),function(){    
  4.  if (jQuery(this).is(':checked')) {
  5.                         // do something
  6.  }
  7. });
  8. }
1 Comment :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!