I just started from: http://jsfiddle.net/FJFFJ/1/ (by Chain dynamically created dropdowns with JQuery)
It’s really good but now I need to change a bit: clone the last group of selects.
ie.:
+-
Argentina | San Juan | Rawson
Chile | Santiago | Chiñihue
Then, if I click at “+”, it will clone
Chile | Santiago | Chiñihue
instead of the first one.
This is actually a harder question than I thought it would be. Apparently when you clone the set of SELECT elements it can’t change to something which isn’t displayed. Took me about an hour or so to figure out exactly what was going on, good challenge, thanks!
What I wound up doing is cloning your template and changing the values manually AND calling the “change” event manually, so that the correct options would be available in the secondary and ternary SELECT elements.
Version 1: http://jsfiddle.net/m4JTQ/2/
Version 2 (this is a modified version getting rid of the i iterator: http://jsfiddle.net/Zf7xb/1/
Here’s the code in case the jsfiddle eventually goes away.
No i iterator in this version, it is a bit cleaner.