• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Date Differences.

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

Please provide me support and alternative solution to the following mention problem. I would be grateful to you.

I have two text boxes on the page named PSDate(means start date) and PFDate(means final date).

While saving the form i have to check final date should be greater than the start date.

I'm not able to get the value entered by the user in the text boxes.

function checkdate1()
{
<%
Date d1 = DateFormat.parse(%> document.CreateProject.PSDate.value <%);
Date d2 = DateFormat.parse(%> document.CreateProject.PFDate.value <%);
int check = D1.compareTo(D2);
if(check==0)
{
System.out.println("You can't enter the same date");
}
else if (check>0)
{
System.out.println("You can't enter the previous date");
}
%>

}

Thanks in Advance.
 
Ranch Hand
Posts: 225
Spring Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

When you have written the above code (in the begining/middle/last)in the JSP file.
And when you are calling this function.(on button click etc).
Kindly give more details for your problem.


***********************************
Tip: Modesty is all virtue.
***********************************
 
Pulkit Malhotra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have written the code in the middle of the jsp other functions.

I'm calling it onClick of save button.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't quite tell from the code, but it looks like you're mixing JSP code (which runs on the server, long before the page gets to the browser) with JavaScript code (which runs in the browser). JSP code doesn't have access to form fields, nor can JavaScript code call Java functions. This article should make things clearer.
[ May 22, 2007: Message edited by: Ulf Dittmer ]
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

As far as I understand is you are trying to generate
Date d1 = DateFormat.parse(%> document.CreateProject.PSDate.value <%);
to something as
Date d1 = DateFormat.parse("10/12/2007");

This wouldn't work. This code wouldn't compile.

Keep in mind that whatever you write in the JSP is converted to java code. Now this happens only once. Now when you are calling function checkdate1() it's not that it will call the java method and generate the output.

You would have to put in a function in javascript for what you want in java or you could use AJAX for the same. I would suggest using a javascript function if it's just date parsing.
 
Pulkit Malhotra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.

Can you suggest me any other way to meet the requirement ?

Requirement :-

User inputs two dates(start date and final date) i have to check final date should be greater than the start date.

Tools i'm using JSP, JAVA , Mysql database and Sun App's Server.
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pulkit,

Why dont you use the JavaScript Date related functions?

These sites may help you to certain extent.

  • guistuff
  • JavaScript Date and Time
  • W3Schools JavaScript Date



  • Using JavaScript Date Objects to validate would make your task easy!

    HtH.
    [ May 22, 2007: Message edited by: Raghavan Muthu ]
     
    Pulkit Malhotra
    Ranch Hand
    Posts: 30
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Raghavan Muthu,


    Thanks for your reply.
     
    There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic