Dec 11

Jquery makes a lot of things really easy. This one, not so much. Take this Select as an example:

SOURCE:

<select id="sort_by" name="sort_by"><option value="F%3Dlistingid%3A1%7Csmallphotos%3A1%7Clistingseopath%3A1%7Cpropertyname%3A1%7Cpropertycity%3A1%7Cpropertystate%3A1%7Clistingpricelow%3A1%7Clistingpricehigh%3A1%7Clistingbedlow%3A1%7Clistingbedhigh%3A1%7Cwebtollfree%3A1%7Clatitude%3A1%7Clongitude%3A1%7Cgeocode%3A1%7Ccityseopath%3A1%7Cfrontcover%3A1%7Cmsa_code%3A1%26N%3D5875%26Nao%3D0%26Nf%3Dgeocode%7CGCLT+48.803100%2C-102.245600+5%26Ns%3Dsortpropertyname%7C1%26Ntk%3Dshowapartment%26Ntt%3D1%26Nu%3Dlistingid%26Ns%3Dsortorder%7C0">Best Match</option>
<option value="F%3Dlistingid%3A1%7Csmallphotos%3A1%7Clistingseopath%3A1%7Cpropertyname%3A1%7Cpropertycity%3A1%7Cpropertystate%3A1%7Clistingpricelow%3A1%7Clistingpricehigh%3A1%7Clistingbedlow%3A1%7Clistingbedhigh%3A1%7Cwebtollfree%3A1%7Clatitude%3A1%7Clongitude%3A1%7Cgeocode%3A1%7Ccityseopath%3A1%7Cfrontcover%3A1%7Cmsa_code%3A1%26N%3D5875%26Nao%3D0%26Nf%3Dgeocode%7CGCLT+48.803100%2C-102.245600+5%26Ns%3Dsortpropertyname%7C1%26Ntk%3Dshowapartment%26Ntt%3D1%26Nu%3Dlistingid%26Ns%3Dsortpropertyname%7C0">Property Name A to Z</option>
</select>

When you perform a selection and want to do some onclick magic, how to get the current selected option text? Like this:

$('#sort_by')[0].options[$('#sort_by')[0].selectedIndex].text

Told it wasn’t pretty. Thanks Troy for helping.

Tagged with: