Reputation: 5805
I need to get a selected item from drop menu,
I am using this script : LINK This is my code I just need to get values in javascript:
function checkData() {
var pagesObj = document.getElementById("website2");
alert(pagesObj.options[pagesObj.selectedIndex].value);
}
$(document).ready(function() {
$.ajax({
url: "get_data.php",
cache: false,
dataType: 'json',
data: {},
success: function(data) {
for (var i = 0; i < data.results.length; i++) {
if(data.results[i].value != '0' ) {
oHandler = $("#websites2").msDropDown().data("dd");
oHandler.add({text:'', value:'', title:''});
oHandler.add({text:data.results[i].text,value:data.results[i].value,title:data.results[i].title});
}
}
}
});
});
This checkData()
function is giving me error that option is not defined and it is null
EDIT:
Html:
<select name="websites2" id="websites2" onChange="checkData()" style="width:200px;"tabindex="1"></select>
Upvotes: 1
Views: 3153
Reputation: 122414
Since you have jQuery
$('#websites2').val()
should do it, though I've found that a bit unreliable on Opera just recently. The following works reliably for me on all the browsers I've tested:
$('#websites2 option:selected').val()
Upvotes: 1
Reputation: 10408
I believe it is as simple as this (using jQuery):
var selectedIndex = $("#websites2").val();
Upvotes: 1