From your description, I suggest you could use Jquery ‘s selector to get DropDownList’s selected value, then you could use each() method to iterating array, the code as below.
//compare function
function CheckDrodowns() {
var array = ["model1", "model2", "model3", "model4"];
var s = $("#DropDownList1 option:selected").text();
$.each(array, function (index, value) {
//ignore case
if (value.toLowerCase == s.toLowerCase) {
//your code
}
});
}
Hope this can help you. If you have any question and confusion about the problem. Please don't hesitate to let me know.
Best regards
Cathy
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
26 Points
98 Posts
JAVASCRIPT ARRAY COMPARISON with dropdownlist selected vlue
Aug 19, 2016 11:53 AM|sanjaykumar pushadapu|LINK
plz say one example
Member
497 Points
147 Posts
Re: JAVASCRIPT ARRAY COMPARISON with dropdownlist selected vlue
Aug 19, 2016 02:33 PM|Janshair Khan|LINK
Greetings,
Probably this jsfiddle sample might help to solve your issue.
Star
8670 Points
2882 Posts
Re: JAVASCRIPT ARRAY COMPARISON with dropdownlist selected vlue
Aug 22, 2016 09:20 AM|Cathy Zou|LINK
Hi sanjaykumar...,
From your description, I suggest you could use Jquery ‘s selector to get DropDownList’s selected value, then you could use each() method to iterating array, the code as below.
Hope this can help you. If you have any question and confusion about the problem. Please don't hesitate to let me know.
Best regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
111 Points
76 Posts
Re: JAVASCRIPT ARRAY COMPARISON with dropdownlist selected vlue
Aug 22, 2016 09:54 AM|mcavickymas|LINK
var cars = ["Saab", "Volvo", "BMW"];
var ddlVal=ddlCarTypes.SelectedItem.text;
cars.forEach(function (item, index, array) {
if(item==ddlVal)
{
alert(item);
// Write You Code Here for your process
}
});