I have a calendar which allows the user to select dates and there will be a counter. Whenever the user checks a box, the value of the count will increase and this is done using jquery.
<td colspan="7">
You need <%=myCourse.getTotalNoClass()%> classes
<input type="hidden" value="<%=myCourse.getTotalNoClass()%>" id="myCourse" name="classCount">
</br> No of Classes selected:
<b><input type="text" id="count-class" name="selectedClass" value="<%=session.getAttribute("selectedClass") %>"></b>
</td>
I want the count value to be shown on the same page after the user clicks a submit button, and as they continue to check boxes, the value of count will continue to increase until they reach the maximum.
Example in Servlet:
if(classCount == classSelect){
request.getRequestDispatcher("confirm-schedule.jsp").forward(request,response);
} else {
request.getRequestDispatcher("schedule.jsp").forward(request,response);
}
Basically my problem is i am not sure how to update the value="<%=session.getAttribute("selectedClass") %>"
as jquery will affect it. The value is able to be stored, but the jquery keeps starting the count on 0. how do i do make sure that the jquery starts count on the value in value="<%=session.getAttribute("selectedClass") %>"
$(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 );
});
只需在servlet中设置计数器即可
request.setParameter("nameOfYourParameter","theValueYouWantToSet");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.