0

This should be really easy, but I'm a novice at webapps.... I have a simple drop down list in my JSP which I created using <select> and <options>. I've got a javascript function in which I would like to get the selected value and proceed to do other stuff with that value. The list populates correctly, but I can't seem to get the selected value.

<form action="noaction" >
    <select name="selectCounty" onchange="getRegions()">
    <option value="" selected="selected">----- Select A country -----</option>
    <%
        String[] countries = country.getCountryList();
        for(int i = 0; i < country.getCountryCount(); i++)
        {
    %>
        <option id="<%=i%>" ><%=countries[i] %></option>
    <%
        }
    %>
    </select>
</form>

<SCRIPT language="javascript" type="text/javascript">
    function getRegions()
    {
        oListBox = document.forms[0].selectCountry

        alert(oListBox.options[1].text);
    }
    
</SCRIPT>
1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by fraenckel
0

I figured it out... I needed to add this to the function call in the form, and then process if in the function...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.