?
Solved

Jquery and switch statement

Posted on 2011-09-30
22
Medium Priority
?
372 Views
Last Modified: 2012-05-12
I have the drop down that triggers  second drop down. Inside of that
code I am using switch statement so switch does not seems to work correctly
because every time I execute and it execute all cases and I do have break after each case

0
Comment
Question by:erikTsomik
[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
  • 11
  • 7
  • 4
22 Comments
 
LVL 15

Expert Comment

by:Eyal
ID: 36894347
probably break; is missing in the end of each case
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36894351
NO I do have a break
0
 
LVL 15

Expert Comment

by:Eyal
ID: 36894359
post the code
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 82

Expert Comment

by:leakim971
ID: 36894360
ok there's no bug with standard javascript function
you must show we your code to know where you make the mistake
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36894386
$('#type').change(function () {
            $("#Message").parent().hide();
            
            switch ($(this).val()){
                  case "0":
                        
                        $("#Message").parent().hide();
                        
                  break;
                  case "1":
                        

                        //check the value of the needAudience ONLY if selection of the menu Type =1 (System Page).Also add menu link message
                        $("#link").change(function () {
                              //alert($("#link").val());
                              $.ajax({
                                    url: "val,
                                    dataType: "json",
                                    cache: false,
                                    type: "post",
                                    contentType: "application/json; charset=utf-8",
                                    success: function(data){
                                          
                                          
                                          if (data.data[0].message.length > 0){
                                                
                                                temp = data.data[0].message;
                                                
                                                $("#Message").parent().show();
                                                $("#Message").text(temp);
                                                
                                          }else{
                                                $("#Message").parent().hide();
                                                $("#Message").text('');
                                          }
                                          

                                    }
                              });

                        }).change();
                  
                  break;
                  case "2":
                        
                        
                               
                              
                              $("#link").change(function () {
                              $.ajax({
                              url: "val,
                                    dataType: "json",
                                    cache: false,
                                    type: "post",
                                    contentType: "application/json; charset=utf-8",
                                    success: function(data){
                                    if (data.recordcount > 0) {
                                          if (data.data[0].description.length > 0) {
                                          
                                                temp = data.data[0].description;
                                                
                                                $("#Message").parent().show();
                                                $("#Message").text(temp);
                                                
                                          }
                                          else {
                                                $("#Message").parent().hide();
                                                $("#Message").text('');
                                          }
                                    }else{
                                          $("#Message").parent().hide();
                                          $("#Message").text('');
                                    }
                                    }      
                              }).change();
                              
                        })
                        
                        
                        

                  break;
                  case "3":
                        
                        

                        
                              
                              $("#link").change(function () {
                              $.ajax({
                              url: val,
                                    dataType: "json",
                                    cache: false,
                                    type: "post",
                                    contentType: "application/json; charset=utf-8",
                                    success: function(data){
                                          if (data.recordcount > 0) {
                                                if (data.data[0].description.length > 0) {
                                                
                                                      temp = data.data[0].description;
                                                      //alert(temp);
                                                      $("#Message").parent().show();
                                                      $("#Message").text(temp);
                                                }
                                                else {
                                                      $("#Message").parent().hide();
                                                      $("#Message").text('');
                                                }
                                          }else{
                                                $("#Message").parent().hide();
                                                $("#Message").text('');
                                          }
                                    }      
                              })
                              
                        }).change();
                        });
                        
                        
                        
                  break;
            }
      }).change();
0
 
LVL 15

Expert Comment

by:Eyal
ID: 36894404
debug it in firefox and see what is happening there because code seems to be OK

add debugger; right before the switch statement
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36894406
case 1 and 2 you've

"url": "val,

missing quotes?
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36894409
that is ok . I just remove the real url
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36894414
I use firebug it tells me that I do execute the code 2 or 3 time for no need whre it shoul only be happening once per selection
0
 
LVL 15

Expert Comment

by:Eyal
ID: 36894430
why do you call change()?
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36894437
change so when I arrive on page for edit and I do know what the selections were It will just triggers for me without any selections
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36894491
is there any updates on this
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36894517
what happen when you remove a .change()?
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36894523
when I remove the change nothing will happened
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36894528
...nothing will happened until doing a change on the link?

how many #link do you have in the page
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36894533
1
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 36894569
for the case 2 you've :
					}).change();	
				})
				break;

Open in new window

instead :
					})	
				}).change();
				break;

Open in new window

0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36905115
i've corrected this but it is still doing the same thing . Is something has to do with the case that I reffering to the same id link. But it should not happening because I am calling this in separate case statement
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36906180
is there any other updates
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36906561
could you provide a link to see the page in live?
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36906604
This code in my local machine
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36906628
could you paste your code updated? or your full page?
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

765 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