Your Ad Here

Posted By

misteroneill on 05/27/09


Tagged

form input jquery label


Versions (?)

jQuery Hide Labels and Use Them as Values


 / Published in: jQuery
 

This function loops through a result set of inputs and for each result, takes the value of any associated label, applies it as the value of the result, and hides the label. Assumes that any label with the class "error" is not counted (I use labels with the error class for errors...).

  1. $.fn.labelHide = function(){
  2. return this.each(function(){
  3. var current = $(this);
  4. var id = current.attr("id");
  5. var label = $("label[for='"+id+"']:not(.error)");
  6. if (id.length && label.length) {
  7. current.val(label.text());
  8. label.hide();
  9. }
  10. });
  11. };
  12.  
  13. // Usage: $('input.label-hide').labelHide();

Report this snippet  

You need to login to post a comment.