Mods, please move this thread to the JavaScript forum.
See this thread for a very similar project. The following function (a modified version of the one from that thread) is the only thing you should copy; the functions called and the techniques used in the rest of that thread demonstrate a pattern for using this core function. (The cb in the parameter names stands for callback.)
Code:
function makeDuplicator(button, element, cb_dress, cb_append){
var prototype = element.cloneNode(true);
button.onclick = function(){
for(var i = 0; i < parseInt(prompt('How many more records would you like?')); i++){
//Dress the clone.
var clone = (cb_dress || lazy)(prototype.cloneNode(true));
//Append the clone.
if(cb_append) //Native objects apparently don't like short-circuit operators.
cb_append(clone, element);
else
element.parentNode.appendChild(clone);
}
};
function lazy(e){
return e;
}
}
Bookmarks