Accessing selection direction by mistake of input element

I am trying to store a Javascript Array object in a cookie. But since it didn't work as expected, I found the stringify () function in the json.js. Below is my code:

$(".save").on('click', function(){          
var lhb = [], csb = [], cons = [], vb = [],
      txt = $("#accordion").find('textarea').serialize(),
      lbs = $('.lh:checked').each(function(){ lhb.push($(this).val()); }),
     cbs = $(".cs:checked").each(function(){ csb.push($(this).val()); }),
     cs = $(".cons:checked").each(function(){ cons.push($(this).val()); });
     vs = $(".vul:checked").each(function() { vb.push($(this).val()); });
     scenario = { 
        "textArea" : txt
        "lbs" : lbs,
        "cbs" : cbs, 
        "cs" : cs,
        "vs" : vs
    },
    cardId = $(this).parent().get(0).id;
    save(cardId, scenario);
    retreive(cardId);
});

      

Now in the function save

I am converting the script to JSON object using json.js

function save(cardId, formData){
    $.cookie(cardId, JSON.stringify(formData), { expires: 7, path: '/' });
}

      

And it gives me the following error:

Accessing selection direction on an input element that cannot have a selection.

Can someone help me fix this error. Is my approach the correct one in storing json array in cookie?

thank

+3


source to share


1 answer


$(".save").on('click', function(){          
    var lhb = [], csb = [], cons = [], vb = [],
        txt = $("#accordion").find('textarea').val();

    $('.lh:checked').each(function(){ 
        lhb.push($(this).val()); 
    });
    $(".cs:checked").each(function(){ 
        csb.push($(this).val()); 
    });
    $(".cons:checked").each(function(){ 
        cons.push($(this).val()); 
    });
    $(".vul:checked").each(function() { 
        vb.push($(this).val()); 
    });

    var scenario = { 
        "textArea" : txt,
        "lbs" : lhb,
        "cbs" : csb, 
        "cs" : cons,
        "vs" : vb
    }

    var cardId = $(this).parent().attr('id');

    save(cardId, scenario);
    retreive(cardId);
});

      



you have a syntax error in the script object, there is no ',' after the txt also you misused serialization function and wrong assignments in script objects

+1


source







All Articles