function createElement(parent, id){ template = "
"; $(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(); });