Reputation: 1320
How can i set hiddent attribute in dom using servlet doPost! the HTML is created by servlet as follow:
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>");
HTTP servlet Reqest to get values of creditcard
and expirationDate
fields. using them I'm comparing the fields value to the database and set CCA
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
creditno = request.getParameter("creditcard"); //name of the input field, not id
expiration = request.getParameter("expirationDate"); //name of the input field should be 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 want to access these variables from Javascript in payment.js to give alert! how can i read this in javascript? writing it to a hidden field in DOM ?
Thanks in Advance!
Upvotes: 0
Views: 2110
Reputation: 22711
Do you want something similar,
out.println("<input type='hidden' id='FormName' name='FormName' value='"+HiddenValue+"'>");
In doPost
method,
FormName = request.getParameter("FormName");
Upvotes: 1