0

Guys the following code allows the user to choose the date between september 1st to current date. i am having problem with jquery datepicker code. kindly let me know your views.

>

<% try { sdf = new SimpleDateFormat("yyyyMMdd");

              minDate = new Date();                       // timestamp now
              Calendar cal = Calendar.getInstance();          // get   calendar instance
              cal.setTime(minDate);                           // set cal to date
              cal.set(cal.get(cal.YEAR),cal.SEPTEMBER,1);
              minDate = cal.getTime();

              maxDate = new Date();
              cal.setTime(maxDate);
              maxDate = cal.getTime();            
      }   catch (Exception e)             
      {

              System.out.println(e);                  
      }
      %>      
      <script type="text/javascript">
          var mx = <%=sdf.format(minDate)%>;
          var mv = <%=sdf.format(maxDate)%>;
          $(document).ready(function(){
              $("#revRepDate").datepicker({
              showOn: 'button', buttonImageOnly:
                  true, buttonImage:
              'style/images/icon_cal.png',
                   dateFormat: 'yymmdd' });
                  }); $("#revRepDate").datepicker('option',{minDate:mx
               , maxDate:mv }); 

1
  • In a jsp page I imported both java.util.Date and java.text.SimpleDateFormat, but when I use var mx = '<%=sdf.format(minDate)%>'; I obtain the sdf cannot be resolved and minDate cannot be resolved exceptions. Any suggestions?
    – Sefran2
    Nov 11, 2012 at 18:45

1 Answer 1

1

You'll need quotes:

var mx = '<%=sdf.format(minDate)%>';
var mv = '<%=sdf.format(maxDate)%>';
4
  • 1
    You can leave "guess" away. Javascript string variables have to be quoted anyway.
    – BalusC
    Nov 3, 2010 at 12:24
  • thanks , i have another problem , i want to show calendar from september 2010 to current date. for example consider if i am spoolin a report on 12th january 2011 ,i should allow calendar selection from 1st september 2010 to 12th janyary 2011 . how to set the date to 1st sep 2010 from current date(if current date is january 11th 2011). Nov 3, 2010 at 13:06
  • I didn't understand the 2nd question. Perhaps you can create a new question with it, providing a better explanation?
    – Bozho
    Nov 3, 2010 at 13:29
  • new question added stackoverflow.com/questions/4087585/… Nov 3, 2010 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.