function swapProd()
{
var image = document.getElementById("prodImage");
var dropd = document.getElementById("prodDrop");
image.src = "images/ej/" + prodArrJS[dropd.value][2] + ".jpg";
}

the function is on an onchange in a form dropdown where "prodDrop" is the option field. "prodArrJS" is a 2d array. It's not accepting "dropd.value".

share|improve this question
1  
Well, what does it do? Does it give an error? Not do anything? Blow up your computer? Make waffles fall from the sky? Please be more specific. – Doorknob Aug 31 '13 at 2:01
    
test your dropd.value using alert. either it is not reading any collection or it doesn't not have value at index 2 – HaBo Aug 31 '13 at 2:04
    
Sorry. It doesn't do anything in this dimension, and stops the function. The dropd.value is working if I display it on a field, for example. And the array is working if I put a number in the brackets instead of dropd.value. – roberto Aug 31 '13 at 2:11
    
I don't know if this has anything to do with it: the prodArrJS array was created like this: var prodArrJS = <?php echo json_encode($products);?> – roberto Sep 2 '13 at 18:32

check this demo fiddle,

I have added values to two dimensional array from two dropdown lists

array[0][1]=[document.getElementById("mySelect").value],["hello"];

or

array.push([document.getElementById("mySelect").value],[document.getElementById("second").value]);
share|improve this answer
1  
Thanks, but I'm trying to get the value from the array, not to put one into it. – roberto Sep 2 '13 at 18:28

The '.value' property returns the contents of the input as a string and unless your 'prodArrJS' is an Object (which I have a suspicion it isn't), your trying to access a value at an index using a string. Try doing 'parseInt(dropd.value)'.

share|improve this answer
    
Just going to point out here that all keys are Strings, meaning ['foo']['0'] is "foo" – Paul S. Aug 31 '13 at 2:33
1  
Thanks, but parseInt is not doing anything either. – roberto Sep 2 '13 at 18:29
1  
Yes, the key works as string or as number.Still, the document.getElementById("x").value – roberto Sep 2 '13 at 19:38
    
GOT TIMEOUT ON LAST COMMENT.Yes, the key works with strings or numbers as well (if that is the case). Still, the document.getElementById("x").value is not working within the array brackets. Not as parseInt() or Number(), or by assigning it to another variable and using that either. – roberto Sep 2 '13 at 19:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.