Issue
The following piece of code when ran produces "undefined".
var getList = document.getElementById('lbExercises').option;
console.log(getList);
The HTML I wish to get the data from is as follows:
<select id="lbExercises" class="listBox" style="height:400px;width:350px;"
name="lbExercises" size="4">
<option value="1270">Value I want to Extract 2</option>
The issue is with my JS code - if it helps I'm running my code by using
phantomsjs filename.js
Solution
You could get the first value of the first option like this:
var getList = document.getElementById('lbExercises');
console.log(getList.options[0].value);
See jsFiddle:
This is how you would assign it to an element of an array:
var anArray = new Array();
anArray[0] = 123;
anArray[1] = 456;
anArray[2] = 789;
// assign the new value
anArray[1] = getList.options[0].value;
console.log(anArray[1]);
See jsFiddle:
Answered By - hutchonoid
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.