Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Date Differences.  RSS feed

 
Pulkit Malhotra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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.
 
Baseet Ahmed
Ranch Hand
Posts: 225
Java Notepad Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • 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 ]
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
    • Quote
    • Report post to moderator
    Hi Raghavan Muthu,


    Thanks for your reply.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!