[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

jquery onchange function problem

Posted on 2015-02-06
8
Medium Priority
?
122 Views
Last Modified: 2015-02-06
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/
0
Comment
Question by:Isaac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 40594378
creates a copy of html elements
You obviously know what jQuery.clone() does, but you want to prevent it from "duplicating"?
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 40594402
Does this get you any closer?

http://jsfiddle.net/t28sv760/14/
0
 
LVL 5

Author Comment

by:Isaac
ID: 40594415
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/
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 38

Expert Comment

by:Tom Beck
ID: 40594431
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?
0
 
LVL 5

Author Comment

by:Isaac
ID: 40594445
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"?
0
 
LVL 2

Expert Comment

by:E-Risk
ID: 40594495
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>");
0
 
LVL 38

Accepted Solution

by:
Tom Beck earned 2000 total points
ID: 40594530
The variable copyFilterBy will be out of scope unless it's global.

If you only want the text from the options inside the select, clone() is not the right function.

Here's an updated jsfiddle where I have added a second select so there's one for each possibility in the top drop down. Then I added a data-value attribute to the select whose value matches the value in the top drop down option.

Now you can create the dynamic <ul> out of the text nodes of each select's options and switch back and forth between them.

http://jsfiddle.net/t28sv760/16/
0
 
LVL 5

Author Closing Comment

by:Isaac
ID: 40594579
This works for me.  I have another similar question that I will post in a few minutes.
Thnaks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question