How do i get input value to jquery in JSP?

Multi tool use


How do i get input value to jquery in JSP?
I am doing a calendar where users are required to select multiple dates which are checkboxes. As they check each box, the counter will increase.
For them to select the values on the next month, they would have to go through a submit button and the counter will be stored in a session in the servlet and it will bring them back to the same JSP page (if they did not select the maximum number of dates) retrieved using session as well.
However, my problem is whenever they go onto the next month, the counter will be set back to 0 but the value does show the number of checked boxes previously when I <%System.out.println("class taken="+session.getAttribute("selectedClass")); %>
<%System.out.println("class taken="+session.getAttribute("selectedClass")); %>
Input value (JSP):
No of Classes selected: <b><input type="text" id="count-class" name="selectedClass" value="<%=session.getAttribute("selectedClass") %>"></b>
Jquery:
$(document).ready(function(){
$("#submitDates").attr('disabled', 'disabled');
$("input[name=date]").change(function(){
var max= $("#myCourse").val();
if( $("input[name=date]:checked").length == max ){
$("input[name=date]").attr('disabled', 'disabled');
$("#submitDates").removeAttr('disabled');
$("input[name=date]:checked").removeAttr('disabled');
}else{
$("input[name=date]").removeAttr('disabled');
}
});
var countChecked = function() {
var n = $( "input:checked" ).length;
$("#count-class").val( n );
};
countChecked()
$( "input[type=checkbox]" ).on( "click", countChecked );
});
How do I update the number of counts based on the value in input?
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.