/ Published in: Rails
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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