0

I have a jsp page with the following:

<select name="classTitle" id="classTitle">
                <option value="-1" name="title">Select class</option>
                <%
                    try{
                    String qr="select * from class";
                    Class.forName("com.mysql.jdbc.Driver").newInstance();
                    Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/lab3","root","");
                    Statement stm=conn.createStatement();
                    ResultSet rs=stm.executeQuery(qr);
                    while(rs.next()){
                    %>
                    <option id="selectedClass" value="<%=rs.getString("classTitle")%>"><%=rs.getString("classTitle")%></option>

                    <%


                    }//end while

                    }//end try
                    catch(Exception ex){
                    ex.printStackTrace();
                    out.println("Error "+ex.getMessage());
                    }
                 %>

            </select>

I want to add to the same form another field which will hold the corresponding class size (stored in table class) for the particular class selected. Then those values will be passed to the Servlet.

So far I have tried

<script>
  $( '#classTitle' ).on( 'change', function( e ){
  $("#results").html("You selected: " + selected);
  });
</script>

and

<div id="results"></div>

for testing - does not work (may be because the original form is itself in a pop up window).

AxelH
  • 14,325
  • 2
  • 25
  • 55
KTM950
  • 63
  • 1
  • 1
  • 8
  • What are you expecting with this code ? `selected` is undefined here. So it would be complicated. Have you search "jquery selected option onchange" ? You should find some answer. – AxelH Jan 30 '17 at 11:32
  • Possible duplicate of [jQuery get value of select onChange](http://stackoverflow.com/questions/11179406/jquery-get-value-of-select-onchange) – AxelH Jan 30 '17 at 11:35

1 Answers1

0

i have check your code without query.your code should be in following way

<script>
$(document).ready(function(){
    $('#classTitle').on('change', function(e) {
        $("#results").text("You selected: " + $(this).val());
    });
});

</script>

<select name="classTitle" id="classTitle">
    <option value="-1">Select class</option>
    <option value="q">ffffffffffff</option>
</select>

<div id="results"></div>
Sanjay
  • 2,481
  • 1
  • 13
  • 28