I have tried using both of these methods and none seem to retrieve the selected value or text of from the drop down menu.
My HTML:
<select id="sessions">
<option value="0">Choose a Session</option>
<option value="Awesome">Awesome</option>
<option value="test1">test1</option>
<option value="testing">testing</option>
</select>
First Method:
var selectedSession = $('#sessions').options[$('#sessions').selectedIndex].val();
This doesn't even get recognized since I get a an undefined value returned.
Second Method:
var selectedSession = $('#sessions').find(":selected").text();
This returns the string "". A blank. I have tried both val() and text(). And yes, I know the difference between the two.
EDIT:
Tried all of these methods with no success:
var selectedSession = $('#sessions :selected').text();
var selectedSession = $('#sessions').val();
var selectedSession = $('#sessions option:selected').text();
var selectedSession = $('select#sessions').val();
var selectedSession = $('#sessions')[0].options[$('#sessions')[0].selectedIndex].val();
var selectedSession = document.getElementById("sessions").text(); Returns null
Also, to clarify, the javascript is in an external document (eg. external.js) and The variable is global and not inside any function.
Thanks for the help.