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??
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.
A break statement is designed to end a for, while or do-while loop or a switch statement. It has no side effects where you are using it. What are you trying to achieve?
In your specific case, just return false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With