Hi Guys, I am trying to add a function to the TexoTela select box manipulation plug-in (http://www.texotela.co.uk/code/jquery/select/). I am trying to add a function called moveOptions() that will function like a cut & paste from one text box to another. There is already a function called copyOptions() that copies a selected value from one select box to another. I copied the code from copyOptions() to my new function moveOptions() to modify. I figure that the only change would be to remove the selected option from the 1st select box after adding it to the 2nd select box. The concept is simple but my code is yielded strange results. The functionality breaks down when you try to copy multiple options at once. I am relatively new to jquery so I'm hoping that it is something obvious. Any help would be greatly appreciated. Thank you in advance.
You can test out the code here: http://www.digital-magic.biz/guy/cake_1_2_blog_tutorial/blog_wizard/filters/addFilters/14. Here is my function, I commented out all the different things that I have done in an attempt to make it work: /** * Move options to another select (functions like cut and paste) * * @name moveOptions * @author Sam Collett (http://www.texotela.co.uk) * @type jQuery * @param String to Element to move to * @param String which (optional) Specifies which options should be copied - 'all' or 'selected'. Default is 'selected' * @example $("#myselect").moveOptions("#myselect2"); // copy selected options from 'myselect' to 'myselect2' * @example $("#myselect").moveOptions("#myselect2","selected"); // same as above * @example $("#myselect").moveOptions("#myselect2","all"); // copy all options from 'myselect' to 'myselect2' * */ $.fn.moveOptions = function(to, which) { var w = which || "selected"; if($(to).size() == 0) return this; this.each( function() { if(this.nodeName.toLowerCase() != "select") return this; // get options var o = this.options; // get number of options var oL = o.length; for(var i = 0; i<oL; i++) { alert(o[i].value + " -- " + o[i].text + " -- " + o[i].selected); if(w == "all" || (w == "selected" && o[i].selected)) { //alert("1" + o[i].text + o[i].value); //alert(o.toString()); $(to).addOption(o[i].value, o[i].text); $(this).removeOption(o[i].value); //$(this).remove(o[i].value); //this.remove(o[i].value); //alert("2" + o[i].text + o[i].value); } //$(this).removeOption(o[i].value, true); } } ); return this; };