Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
24
rated 0 times [  28] [ 4]  / answers: 1 / hits: 24406  / 11 Years ago, mon, may 6, 2013, 12:00:00

I have a function which selects a text based on the input string. If both matches i make it selected. PFb the function,



function setDropdownTextContains(dropdownId,selectedValue,hfId){
$('#'+dropdownId+' option').each(function(){

if($(this).text() === selectedValue){
$(this).attr(selected, selected);
break;
}
});
$('#'+hfId).val(ModelName doesnt match);
}


I get the below error unlabeled break must be inside loop or switch ... What am i doing wrong??


More From » jquery

 Answers
12

The exception text is quite descriptive. You really can't use break statement inside if clause. In your case you should use return false to stop the .each() iteration.


[#78410] Saturday, May 4, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarrodfletchers

Total Points: 75
Total Questions: 94
Total Answers: 95

Location: Netherlands
Member since Thu, Jul 1, 2021
3 Years ago
;