locked
JAVASCRIPT ARRAY COMPARISON with dropdownlist selected vlue RRS feed

  • Question

  • User616860969 posted

    plz say one example 

    Friday, August 19, 2016 11:53 AM

Answers

  • User-707554951 posted

    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.

                  //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

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 22, 2016 9:20 AM

All replies

  • User-491950272 posted

    Greetings,

    Probably this jsfiddle sample might help to solve your issue.

    Friday, August 19, 2016 2:33 PM
  • User-707554951 posted

    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.

                  //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

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 22, 2016 9:20 AM
  • User429228380 posted

    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
    }
    });

    Monday, August 22, 2016 9:54 AM