-1
<script>
          $(document).ready(function(){
            $("#button").click(function(){
         if(diff1>31)
        {
        alert("You can't extend more than one month");
        }
         else
        {
        var jspcall = "thnks.jsp";
        window.location.href = jspcall;
        }
        });
});

 </script>

And here is my jsp code

                  Date date=edate;
       System.out.println("extend date" + date);

        java.sql.Date content = new java.sql.Date(date.getTime());
java.util.Date exp_date = new java.util.Date(content.getTime());
         java.util.Date cur_date = new java.util.Date();
         System.out.println(cur_date);
 long  diff= exp_date.getTime() - cur_date.getTime();
 long diff1=diff/(24 * 60 * 60 * 1000);

 %>
     <li>
    <button class="submit"> submit </button>

This all in same jsp page. Any other suggestion apart from this?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • in js code, var diff1=<%=diff1%>, try this code. – OQJF Apr 22 '14 at 06:57
  • my javascript is defined before jsp form and script is call after clicking on a button.Then how can I access diff1 variable – user3440874 Apr 22 '14 at 08:00
  • It doesn't matter that the Javascript is defined before the JSP form, the JSP gets evaluated (the java runs and puts the correct value for the Java value) on the server, the Javascript gets run on the client. You move the Java code in the JSP (between `<%` and `%>`) so that it is before the Javascript, and then the Java value is available to make it something like `var diff1=<%=diff1%>` – jedison Apr 22 '14 at 09:41

1 Answers1

1

Use <%= your jsp variable %>

also you can do long route as,

Assign this jsp code result to any Hidden HTML field. Then use hidden field value in your java script code.

Pramod S. Nikam
  • 4,271
  • 4
  • 38
  • 62