Answer the question
In order to leave comments, you need to log in
Why doesn't the javascript array work?
Hello.
The problem is this, the array does not work when it contains text names.
For example, this code works:
var variants = {
'66': {'images_names':[4984534-1_1.jpg,4984534-2_1.jpg], 'v_id':[66]},
'208': {'images_names':[4984534-3_1.jpg,4984534-4_1.jpg], 'v_id':[208]},
};
function changeVariant(){
var variant = $('input[name=variant]:checked'),
val = variants[variant.val()],
images_names = val['images_names'],
v_id = val['v_id'],
image_id = images_names[0],
arr = [];
}
'66': {'images_names':[4984534-1_1.jpg,4984534-2_1.jpg], 'v_id':[66]},
and on But if you work with image IDs, namely var variants , replace withimages_names = val['images_names'],
var variants = {
'66': {'images_ids':[168,156], 'v_id':[66], 'percent':'20'},
'208': {'images_ids':[158,159], 'v_id':[208], 'percent':'84'},
};
Answer the question
In order to leave comments, you need to log in
Pass filenames as strings:
var variants = {
'66': {'images_names':['4984534-1_1.jpg', '4984534-2_1.jpg'], 'v_id':[66]},
'208': {'images_names':['4984534-3_1.jpg', '4984534-4_1.jpg'], 'v_id':[208]},
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question