Getting selected option from the select element
I have a few selects like this:
-
| <select id="theOptions1" name="theOptions1"> |
|
<option>1</option> |
|
<option>2</option> |
|
<option>3</option> |
|
<option>a</option> |
|
<option>b</option> |
|
<option>c</option> |
|
</select> |
I want to pass it to a function that will show me the selected element:
-
| $(function() { |
|
$('#theOptions' + 2)).filterOn('#theOptions' +1, { |
|
'a': ['a'], |
|
'1': ['1'] |
|
}); |
|
}); |
here is a part of the function:
-
| jQuery.fn.filterOn = function(radio, values) { |
|
return this.each(function() { |
|
var select = this; |
|
var options = []; |
|
}); |
|
$(radio).change(function() { |
|
var selectedIndex = $(radio 'option:selected()').Index(); |
|
alert("and the text is:" + selectedIndex); |
|
}); |
|
}); |
|
}); |
|
}; |
but
- alert("and the text is:" + selectedIndex);
doen't seem to work. Is it the right syntax?
- var selectedIndex = $(radio 'option:selected()').Index();