Jquery and switch statement

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

LVL 19
erikTsomikSystem Architect, CF programmer Asked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
for the case 2 you've :
					}).change();	
				})
				break;

Open in new window

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

Open in new window

0
 
EyalCommented:
probably break; is missing in the end of each case
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
NO I do have a break
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
EyalCommented:
post the code
0
 
leakim971PluritechnicianCommented:
ok there's no bug with standard javascript function
you must show we your code to know where you make the mistake
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
$('#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
 
EyalCommented:
debug it in firefox and see what is happening there because code seems to be OK

add debugger; right before the switch statement
0
 
leakim971PluritechnicianCommented:
case 1 and 2 you've

"url": "val,

missing quotes?
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
that is ok . I just remove the real url
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
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
 
EyalCommented:
why do you call change()?
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
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
 
erikTsomikSystem Architect, CF programmer Author Commented:
is there any updates on this
0
 
leakim971PluritechnicianCommented:
what happen when you remove a .change()?
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
when I remove the change nothing will happened
0
 
leakim971PluritechnicianCommented:
...nothing will happened until doing a change on the link?

how many #link do you have in the page
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
1
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
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
 
erikTsomikSystem Architect, CF programmer Author Commented:
is there any other updates
0
 
leakim971PluritechnicianCommented:
could you provide a link to see the page in live?
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
This code in my local machine
0
 
leakim971PluritechnicianCommented:
could you paste your code updated? or your full page?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.