Getting value of Drop Down List - .val() not working
I'm currently using jQuery to supplement an application I'm building using web2py. One of the issues I'm trying to use jQuery to help with concerns some drop down lists that I manually made with HTML. The values for these drop down lists are set in the web2py backend. The resulting HTML looks like this:
- <select name="ddlschool" value="2">
- <option value="1">Lincoln Elementary</option>
- <option value="2">Screaming Eagle Middle School</option>
- <option value="3">Johns Hopkins High School</option>
- </select>
I pulled this HTML directly from the Google Chrome dev tools. As you can see, the value for
the select is 2. However, the drop down list displays the first item. Therefore, .val()
returns 1. What I was hoping to do was use jQuery to pull the value (2) out of the select tag
and set the selected value to 2, so that the drop down list displays "Screaming Eagle Middle
School"
and not "Lincoln Elementary".
Is there another function that I'm not aware of that would do this for me? Or is it possible
to get
the text for the tag and strip out the value? I appreciate any help that anyone could give.