-1

I have an array of arrays declared as the following:

var rangeValues = [[0.001, 0.01], [0.0000001, 0.000001]];

This array is used to fill the values of a drop down, since I essentially need a tuple for each drop down item's value. I proceed to access the values of the drop down with the following:

rangeTuple = document.getElementById('rangeSelection').value;
console.log(rangeTuple);

selectedMinRange = rangeTuple[0];
selectedMaxRange = rangeTuple[1];
console.log(selectedMinRange +  " | " +  selectedMaxRange[1]);

And I receive the following output:

0.001,0.01
0 | .

In my understanding (albeit limited with JS :) ), rangeTuple should be an array with two items in it. When rangeTuple is logged, it looks correct. However, when I try and assign the items in this tuple to a pair global variables, the values are not the ones I expect.

Any help is appreciated,

1
  • What values are you expecting? What values do you get? Commented Jun 7, 2014 at 18:00

1 Answer 1

2

The value of an input is always a string. You will need to split that string to use it in the way you want:

rangeTuple = document.getElementById('rangeSelection').value;
console.log(rangeTuple);

// split it
rangeTuple = rangeTuple.split(",");

selectedMinRange = rangeTuple[0];
selectedMaxRange = rangeTuple[1];
console.log(selectedMinRange +  " | " +  selectedMaxRange);
Sign up to request clarification or add additional context in comments.

1 Comment

+1. Yeah, the DOM doesn't "hold" a JavaScript object for you as the original object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.