function createElement(parent, id){ template = "<div class=\"filter\" id=\"filter\"><fieldset><legend>Send to filter</legend><select id=\"select" + id + "\"></select><a class=\"addlink\" id=\"button" + id + "\">SEND</a> <span id=\"out" + id + "\"></span></fieldset></div>"; $(template).appendTo(parent); $("#select" + id).load("/filter/options/ #options option"); } function attachEvents(id){ $("#button" + id).bind("click", function(e){ var url = $("#select" + id + " option:selected").val(); $.post("/send/", { "filter": url, "message": id}, function(data){ $("#out" + id).text(data).fadeIn(3000); $("#out" + id).text(data).fadeOut(3000); }); }); } function AddSenders(){ $(".row1").each(function(i){ var url = $(this).find("th").find("a").attr("href"); var url = url.replace(/\//, ""); createElement($(this).find("th"), url); attachEvents(url); }); $(".row2").each(function(i){ var url = $(this).find("th").find("a").attr("href"); var url = url.replace(/\//, ""); createElement($(this).find("th"), url); attachEvents(url); }); } $(document).ready(function() { //do stuff when DOM is ready jQury if(jQuery.url.attr("path") == "/admin/org/message/")AddSenders(); });