Is there a way to set the hidden attribute in the DOM using servlet doPost? The HTML is generated by the servlet as shown below:
out.println("<html>");
out.println("<head>");
out.println("<title>Make payment</title>");
out.println("<script type='text/javascript' src='js/jquery-1.5.2.min.js'></script>");
out.println("<script type='text/javascript' src='js/payment.js'></script>");
out.println("<link type='text/css' href='css/style.css' rel='Stylesheet' />");
out.println("</head>");
out.println("<body>");
out.println("<div class='bg-light' style='width: 200px; height: 200px; position: absolute; left:50%; top:50%; margin:-100px 0 0 -100px; padding-top: 40px; padding-left: 10px;'>");
out.println("<input id='reservationID' style='display: none' value='"+rb.reservationID+"' />");
out.println("<div>Credit Card Number : </div>");
out.println("<div><input id='creditcard' onKeyPress='return checkIt(event);' type='text' name='creditcard' maxlength='16' /></div>");
out.println("<div>ExpirationDate : </div>");
out.println("<div><input id='expirationDate' type='text' onKeyPress='return checkIt(event);' name='expirationDate' maxlength='4' /></div>");
out.println("<span style='font-size: 75%;'>"+Error+"</span>");
out.println("<div><input type='button' name='buttonsave' value='Make Payment' onclick='makePayment("+rb.reservationID+");' /></div>");
out.println("<div><input type='button' name='buttoncancel' value='Cancel Payment' onclick='cancelPayment("+rb.reservationID+");' /></div>");
out.println("</div>");
out.println("</body>");
out.println("</html>");
An HTTP servlet request is used to retrieve values from the creditcard
and expirationDate
fields. These values are then compared to the database to set CCA.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
creditno = request.getParameter("creditcard");
expiration = request.getParameter("expirationDate");
if (request.getParameter("buttonsave") != null) {
UserBean us = new UserBean();
boolean check = us.checkCC(userID, request.getParameter("creditcard"), request.getParameter("expirationDate"));
if (check == true) {
CCA = 1;
} else {
CCA = 0;
}
}
Now, I need to access these variables from JavaScript in payment.js to display an alert. How can I achieve this? Can I write them to a hidden field in the DOM?
Thank you in advance!