How to display result of SQL in alert message using javascript in jsp?

Below is COUNT SQL statement in jsp. As you can see my dropdown of studentlevel will display the count of each level. If a user clicks on one of the dropdowns, then if the studentlevel achieved the maximum number of 5 people the system will produce an alert message but I failed to do so. I think my method is wrong. Please help me to make it happen.

  <%

try{

        Connection conn = connectionManager.getConnection();

        String searchQuery = "Select count(studentlevel) AS COUNTER1 FROM student WHERE studentlevel = '1'";
        OraclePreparedStatement pst = (OraclePreparedStatement) conn.prepareStatement(searchQuery);
        OracleResultSet rs = (OracleResultSet) pst.executeQuery();

        String searchQuery2 = "Select count(studentlevel) AS COUNTER2 FROM student WHERE studentlevel = '2'";
        OraclePreparedStatement pst2 = (OraclePreparedStatement) conn.prepareStatement(searchQuery2);
        OracleResultSet rs2 = (OracleResultSet) pst2.executeQuery();

        String searchQuery3 = "Select count(studentlevel) AS COUNTER3 FROM student WHERE studentlevel = '3'";
        OraclePreparedStatement pst3 = (OraclePreparedStatement) conn.prepareStatement(searchQuery3);
        OracleResultSet rs3 = (OracleResultSet) pst3.executeQuery();
%>

<div class="select-wrapper">Student Level:
                                    <select name="studentlevel" id="studentlevel" required>
                                            <option value="">- Student Level -</option>
<%  

                                                while(rs3.next()){

                                                    System.out.println("The sql : "+searchQuery3);                      
                                                    count3 = rs3.getString(1);

                                            %>
                                            <option value="3">3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<%= count3 %>/5]</option>
                                            <p id="message5"></p>
                                            <%} %>
                                            <%  

                                                while(rs2.next()){

                                                    System.out.println("The sql : "+searchQuery2);                      
                                                    count2 = rs2.getString(1);

                                            %>
                                            <option value="2">2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<%= count2 %>/5]</option>
<p id="message6"></p>                                               
<%} %>
                                            <%  

                                                while(rs.next()){

                                                    System.out.println("The sql : "+searchQuery);                       
                                                    count1 = rs.getString(1);

                                            %>
                                            <option value="1">1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<%= count1 %>/5]</option>
<p id="message7"></p>                                               
<%} %>
                                        </select>
                                    </div>

JAVASCRIPT

<script>
var c, d, e, text5, text 6, text7;
c = document.getElementById("count3").value;
d = document.getElementById("count2").value;
e = document.getElementById("count1").value;
if(c>0 || c<=5)
{
text5 = "The Class is Already Full, Please Contact the Clerk for Futher Information.";
}
else
    {text5= "";
    }

if(d>0 || d<=5)
{
text6 = "The Class is Already Full, Please Contact the Clerk for Futher Information.";
}
else
    {text6= "";
    }

if(e>0 || e<=5)
{
text7 = "The Class is Already Full, Please Contact the Clerk for Futher Information.";
}
else
    {text7= "";
    }
document.getElementById("message5").innerHTML = text5;
document.getElementById("message6").innerHTML = text6;
document.getElementById("message7").innerHTML = text7;
</script>