Return to Snippet

Revision: 21691
at December 18, 2009 11:57 by smoothdzion


Initial Code
def name_copy(model)
    '<script type="text/javascript" charset="utf-8">
      var n = $("input#' + model + '_name");
      var t = $("input#' + model + '_title");
      var st = $("input#' + model + '_seo_title");
      var su = $("input#' + model + '_seo_url");
      
      n.blur(function(){
        if(t.val()==0){
          t.val(n.val());
        };
        
        if(st.val()==0){
          st.val(n.val());
        };
        
        if(su.val()==0){
          su.val(n.val());
        };
      });
    </script>'
  end

Initial URL


Initial Description
I needed to copy the value of one field to a couple of others in case users decided to forget to fill them out.  Using jQuery and added it to a helper because I was using in multiple places.  Created variables to make it more readable.

Initial Title
RoR Helper - Copy Input Value if Empty

Initial Tags
rails, ruby, jquery

Initial Language
Rails