jsp - How to pass a scriptlet variable into onclick() function call to javascript -
i need read variable , have pass argument function after onclick(). using jsp, reading variable using scriptlets
<% int lateregdays = 6;%>
i passing variable as
onclick="displaydatepicker('starttestadminno','mdy',<%=lateregdays %>,120,0,3);"
but, unable pass valueof 6. string "<%=lateregdays%>" being passed function. however, when tried print value using alert, worked. changes did is,
onclick='<%="alert("+lateregdays+")"%>'
in similar fashion, need know, how pass arguments function scriptlet variable. entire code snippet is:
<td><input name="starttestadminno"></td> <td> <chtml:img srckey="order.calendar.search" onclick="displaydatepicker('starttestadminno','mdy',<%=lateregdays %>,120,0,3);" altkey="order.calendar.alt_search" bundle="prompt" /> </td>
i need stuckand don't know how pass multiple arguments along scriptlet variable
scriplets
generate html content when browser loads jsp page, if want use inside javascript, need capture lateregdays
variable during page loading time below:
<script> var lateregdays; <!-- global variable --> function init() { lateregdays = '<%= lateregdays %>'; } function displaydatepicker(...) { // lateregdays var } </script> <body onload="init()"> <!-- code --> </body>
p.s.: scriplets
legacy code (invented in 2000 sun), not best practice use them, avoid them using latest front-end technology stack presentation layer.
Comments
Post a Comment