erikTsomik
asked on
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
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
probably break; is missing in the end of each case
ASKER
NO I do have a break
post the code
ok there's no bug with standard javascript function
you must show we your code to know where you make the mistake
you must show we your code to know where you make the mistake
ASKER
$('#type').change(function () {
$("#Message").parent().hid e();
switch ($(this).val()){
case "0":
$("#Message").parent().hid e();
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.leng th > 0){
temp = data.data[0].message;
$("#Message").parent().sho w();
$("#Message").text(temp);
}else{
$("#Message").parent().hid e();
$("#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().sho w();
$("#Message").text(temp);
}
else {
$("#Message").parent().hid e();
$("#Message").text('');
}
}else{
$("#Message").parent().hid e();
$("#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().sho w();
$("#Message").text(temp);
}
else {
$("#Message").parent().hid e();
$("#Message").text('');
}
}else{
$("#Message").parent().hid e();
$("#Message").text('');
}
}
})
}).change();
});
break;
}
}).change();
$("#Message").parent().hid
switch ($(this).val()){
case "0":
$("#Message").parent().hid
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.leng
temp = data.data[0].message;
$("#Message").parent().sho
$("#Message").text(temp);
}else{
$("#Message").parent().hid
$("#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.
temp = data.data[0].description;
$("#Message").parent().sho
$("#Message").text(temp);
}
else {
$("#Message").parent().hid
$("#Message").text('');
}
}else{
$("#Message").parent().hid
$("#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.
temp = data.data[0].description;
//alert(temp);
$("#Message").parent().sho
$("#Message").text(temp);
}
else {
$("#Message").parent().hid
$("#Message").text('');
}
}else{
$("#Message").parent().hid
$("#Message").text('');
}
}
})
}).change();
});
break;
}
}).change();
debug it in firefox and see what is happening there because code seems to be OK
add debugger; right before the switch statement
add debugger; right before the switch statement
case 1 and 2 you've
"url": "val,
missing quotes?
"url": "val,
missing quotes?
ASKER
that is ok . I just remove the real url
ASKER
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
why do you call change()?
ASKER
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
ASKER
is there any updates on this
what happen when you remove a .change()?
ASKER
when I remove the change nothing will happened
...nothing will happened until doing a change on the link?
how many #link do you have in the page
how many #link do you have in the page
ASKER
1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
ASKER
is there any other updates
could you provide a link to see the page in live?
ASKER
This code in my local machine
could you paste your code updated? or your full page?