Link to home
Start Free TrialLog in
Avatar of Isaac
IsaacFlag for United States of America

asked on

jquery onchange function problem

In the jsfiddle is code that creates a copy of html elements.  It works fine but duplicates. How can I prevent it from duplicating? What do I test for?

Also, the following line never gets executed?
$("#tabs").prepend("<ul id='tabIndex'><li>"+copyFilterBy+"</li></ul>");

Open in new window


http://jsfiddle.net/isogunro/t28sv760/13/
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

creates a copy of html elements
You obviously know what jQuery.clone() does, but you want to prevent it from "duplicating"?
Does this get you any closer?

http://jsfiddle.net/t28sv760/14/
Avatar of Isaac

ASKER

Yes, I would like to prevent it from duplicating, if possible.  I know, sounds crazy.
Check out the onchange
http://jsfiddle.net/isogunro/t28sv760/13/
So what to you want to show up in #tabs div if not a copy of .controlGroup? Do you want just the text inside the select options to show up as list items?
Avatar of Isaac

ASKER

Yes, text inside the select options.

As I toggle back an forth, is there a way to remove what I duplicated before I add it again when the drop down is "Punctuality"?
Avatar of E-Risk
E-Risk

Something like this might get you closer based upon you wanting to remove what you duplicated before you add it again when the drop down is "Punctuality".

      $("#DashboardToggle select").change(function()
      {
        alert("HEllo Dashboard");
            var val = $(this).find("option:selected").val();
            if(val == "GLChart")
            {
            alert("Show GLChart");
            }
            if(val == "Punctuality")
            {
                  alert("Show Punctuality");
            var copyFilterBy = $(".controlGroup").clone();
            $(copyFilterBy).appendTo("body");
            $(".controlGroup" ).first().remove();
            }
      });

alert("outside");
$("#tabs").prepend("<ul id='tabIndex'><li>"+copyFilterBy+"</li></ul>");
ASKER CERTIFIED SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Isaac

ASKER

This works for me.  I have another similar question that I will post in a few minutes.
Thnaks