Jquery / javascript: arrays

I am starting with Javascript / jQuery and I hope someone can help me with the following:

I have a simple form (7 questions, 3 switches / answers to a question - except for question 5 with 8 possible options) and based on the selected answers, when the user clicks "view-advice", I want to display the corresponding tips (a combination of 38 possible tips) below the form. I gave the values ​​"a", "b", "c", ... for the radio buttons, and I collect them in an array. The part where the script warns that the array is working fine. I cannot figure out where I show the tips depending on the values ​​in the array.

I would be grateful for your help! Thank!

Here is the code:


var laArray = new Array();

$('.button-show-advice').click(function(){

    $(":radio:checked").each(function(i){
        laArray[i] = $(this).val();
        if (laArray == ["a","d","g","j","m","u"]) {
        $("#advice-container, #advice1, #advice2").show(); // something is wrong here :(
            };
    })
    alert(laArray) // testing to see if it works

})

+1
3

, , , , jQuery inArray.

, . , , , .

function radioSelected(val) {
  return ($.inArray(val, laArray) != -1);
}

script.

0

, , , 2

function compare_array(array1,array2) {
    var i;
    for(i=0;i=array1.length;i++) {
        if(array1[i]==array2[i]) {
            return false;
        }
    }
    return true;
}

(, -)

function compare_array(array1,array2) {
     return array1.join(",")==array2.join(",");
}
0

HTML-. , - :


var laArray = [];
var compareValues = function(arr1, arr2) {
  $(arr1).each(function(index, el) {
   if(el !== arr2[index]) {
     return false;
   }
  });
  return true;
};

$('.button-show-advice').click(function(){
    $(":radio:checked").each(function(i){
        laArray.push($(this).val());        
    });
   if(compareValues(laArray,["a","d","g","j","m","u"])) {
      $("#advice-container, #advice1, #advice2").show();
   }  
});

EDIT: , });...

0

All Articles