Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
24
rated 0 times [  28] [ 4]  / answers: 1 / hits: 24407  / 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
jarrodfletchers questions
Sat, Sep 25, 21, 00:00, 3 Years ago
Mon, Jan 21, 19, 00:00, 5 Years ago
Sun, Dec 16, 18, 00:00, 6 Years ago
Sun, Nov 4, 18, 00:00, 6 Years ago
;