This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Date foramt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Date foramt " Watch "Date foramt " New topic
Author

Date foramt

Ravi Kumar
Greenhorn

Joined: Apr 08, 2007
Posts: 9
Hi Everybody,

I have 2 text fields iam entering Date as input.
suppose if i click on first text field the second text filed should automatically take date as "dd-MON-YYYY" format.

Thanks in advance
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Do you mean fill the current date in second field, using that specific format, on click of the first field?

Or

Do you want the date in the first field to be printed in second field in that specific format?

Anyways, you can use java.text.SimpleDateFormat class.
Ravi Kumar
Greenhorn

Joined: Apr 08, 2007
Posts: 9
thanks for replying.

Let me put clear.

I have 2 text feilds.In first text field if i entered date.
for Ex:if i entered '09-Apr-2007'the second text filed should automatically display date as '10-Apr-2007'(i,e date+1).

Thanks....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

Do you not hava a Javascript reference avaiulable so that you can inspect the API of the Date class?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ravi Kumar
Greenhorn

Joined: Apr 08, 2007
Posts: 9
i have written a method in javascript.
i have used below method,but it is not supporting..

var dt=new date(ref.setDate(ref.getDate)+1)

pls suggest a quick solution for my problem.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Originally posted by yadav kumar:

var dt=new date(ref.setDate(ref.getDate)+1)



what you are trying to achieve with line of code?
[ April 10, 2007: Message edited by: Saif uddin ]

Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

see here some example to understand how we can play with JavaScript Date Object
Ravi Kumar
Greenhorn

Joined: Apr 08, 2007
Posts: 9
get_date(obj)

var pdate=doucment.frm.getElementSByName("pdate");

if (pdate! =null)

var sdate=new date(pdate.setDate(pdate.getDate)+1);

sdate is getting as null.

please give me soultion.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321


"S" should be small getEelementsByName()
if you are getting a element value by using a form then no need to use this method.

follow the simple way :


and another thing is.



.setDate This method is always used in conjunction with a Date object.



hope it helps..
[ April 11, 2007: Message edited by: Saif uddin ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
getDate is a method so you need to use ()

also getElementsByName is an array

Eric
Ravi Kumar
Greenhorn

Joined: Apr 08, 2007
Posts: 9
First of all thanks for replying .

Main my problem is that iam not able to get the date value

i mean when i call below statment

In javascript

get_date(obj)
{
var pdate=doucment.frm.getElementsByName("pdate");

if (pdate! =null)
{
var pdate=doucment.frm.getElementsByName("pdate");

alert('pdate'+pdate); //pdate is getting as null

var sdate=new date(pdate.setDate(pdate.getDate)+1);
}
}


iam getting as null because iam not able to get the value of pdate

In JSP
String pdate=""

//pdate=request.getParameter("pdate")


input type="text" value="" name="pdate"
javascript:show_calendar('forms[0].pdate');
ahref="javascript:get_Date(this);"

Note: pdate iam passing input as dynamic

Sorry it may contain some syntax errors please ignore it

Thanks
Scott Escue
Ranch Hand

Joined: Jan 20, 2005
Posts: 34
yadav,

You have several people trying to help you with this. It would hep you get a meaningful response if you would post your actual javascript code and your html. There are any number of problems that could prevent you from getting a reference to your input object. If you don't post code, we're all just guessing at things that could possibly be wrong.
Ravi Kumar
Greenhorn

Joined: Apr 08, 2007
Posts: 9
This is below code It's is the main logic.

This is from javascript.

get_date(obj)
{
var pdate=doucment.frm.getElementsByName("pdate");

if (pdate! =null)
{
var pdate=doucment.frm.getElementsByName("pdate");

alert('pdate'+pdate); //pdate is getting as null

var sdate=new date(pdate.setDate(pdate.getDate)+1);
}
}


iam getting as null because iam not able to get the value of pdate

This is from JSP

String pdate=""

"<"input style="width:70px; font-size: 10px;" value=""<"%=pdate%"<"" maxlength="11" name="pdate" type="text""<"
"<"a ="javascript:show_calendar('forms[0].pdate');" href="javascript:get_Date(this);""<"

This reason is before calling show_calendar method it is going to get_Date method as a result pdate is null.

Thanks.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

change you get_date function with this..



hope it works for you..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Date foramt
 
Similar Threads
Calender component
date validation in javascript
h:outputText: Default Value
convert text object to date where date-format is dynamic
Date Difference