We have some date fields in our HTML forms in various places. In the
accounts package we use, there is some pretty nifty date handling.
It has a standardised date format of dd/mm/yyyy and if you enter e.g.
3-12 it will switch it to 3/12/2005
Same applies for e.g. 3:12 etc
Anyone know of some javascript which will do this for our HTML form
fields? Our target format is actually dd-mon-yyyy and it would make it
really nice for users if the system could accept a variety of input
formats and then switch it to a date to our specification. Any
suggestions?
--
jeremy 8 4098
Jeremy wrote: We have some date fields in our HTML forms in various places. In the accounts package we use, there is some pretty nifty date handling.
It has a standardised date format of dd/mm/yyyy and if you enter e.g.
3-12 it will switch it to 3/12/2005
Same applies for e.g. 3:12 etc
Anyone know of some javascript which will do this for our HTML form fields? Our target format is actually dd-mon-yyyy and it would make it really nice for users if the system could accept a variety of input formats and then switch it to a date to our specification. Any suggestions?
The task is trivial, but first you need to ensure that your users can
not introduce ambiguities.
A sample: http://www.mickweb.com/demo/datepicker.html
Mick
In article <j6************ *******@twister .nyroc.rr.com>, Mick White
says... Jeremy wrote:
We have some date fields in our HTML forms in various places. In the accounts package we use, there is some pretty nifty date handling.
It has a standardised date format of dd/mm/yyyy and if you enter e.g.
3-12 it will switch it to 3/12/2005
Same applies for e.g. 3:12 etc
Anyone know of some javascript which will do this for our HTML form fields? Our target format is actually dd-mon-yyyy and it would make it really nice for users if the system could accept a variety of input formats and then switch it to a date to our specification. Any suggestions?
The task is trivial, but first you need to ensure that your users can not introduce ambiguities. A sample: http://www.mickweb.com/demo/datepicker.html
Thanks Mick, perhaps I didn't make myself clear. From what I see, you
are enabling the user to select a date from 3 individual fields and then
displaying the resultinto a 4th field
What I am looking to acheive is a single text field in which the user
may type e.g. 3/12/05 and which, as the cursor leaves the field, is
reformatted to 3-dec-2005.
You said it is trivial: is it really?
thanks
--
jeremy
JRS: In article <MP************ ************@ne ws.individual.n et>, dated
Tue, 25 Oct 2005 15:32:24, seen in news:comp.lang. javascript, Jeremy
<je********@gma il.com> posted : We have some date fields in our HTML forms in various places. In the accounts package we use, there is some pretty nifty date handling.
It has a standardised date format of dd/mm/yyyy and if you enter e.g.
3-12 it will switch it to 3/12/2005
Same applies for e.g. 3:12 etc
Anyone know of some javascript which will do this for our HTML form fields? Our target format is actually dd-mon-yyyy and it would make it really nice for users if the system could accept a variety of input formats and then switch it to a date to our specification. Any suggestions?
If you allow an adaptive variety, you need to be reasonably sure that
there are no unexpected cases that are misinterpreted, because your
users may not notice that the switched form is not as expected.
Better IMHO to provide a set of radio-buttons and/or checkboxes to
choose the current format, and to display by onChange or similar the
date of Christmas in the currently selected format.
Do you go as far as allowing 25.XII.2005, 33/11/22, and 2005-W51-7, for
example?
You could try reading the newsgroup FAQ; see below.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jeremy wrote:
Thanks Mick, perhaps I didn't make myself clear. From what I see, you are enabling the user to select a date from 3 individual fields and then displaying the resultinto a 4th field
What I am looking to acheive is a single text field in which the user may type e.g. 3/12/05 and which, as the cursor leaves the field, is reformatted to 3-dec-2005.
You said it is trivial: is it really?
Yes, but you can never be sure what the user will enter.
function convertDate(val ue){
var v=value.split(/[^\d]/);
v[1]=
['jan','feb','ma r','apr','may', 'jun','jul','au g','sep','oct', 'nov','dec'][v[1]-1];
return v.join("-");
}
alert("3/12/05") // "3-dec-2005"
<input ... onchange="this. value=convertDa te(this.value)" >
You're aware that "3/12/2005" is interpreted as "March 12, 2005" in
North America, are you not?
Mick.
Jeremy wrote: It has a standardised date format of dd/mm/yyyy and if you enter e.g. 3-12 it will switch it to 3/12/2005 Same applies for e.g. 3:12 etc Anyone know of some javascript which will do this for our HTML form fields?
Using my generalized date functions at http://www.javascripttoolbox.com/date/
you could do something like this:
<input type="text" name="date"
onChange="var d=parseDate(thi s.value);if(d== null){alert('Da te format not
recognized!');} else{this.value =formatDate(d,' dd-MMM-yyyy)}">
With the default code, it would automatically recognize and parse dates in
these formats:
y-M-d MMM d, y MMM d,y y-MMM-d d-MMM-y MMM d
M/d/y M-d-y M.d.y MMM-d M/d M-d
d/M/y d-M-y d.M.y d-MMM d/M d-M
You could modify the parseDate function to easily parse more date formats.
You should of course be aware that some values entered will be ambiguous.
1/2/2000 can mean Jan 2, 2000 just as well as Feb 1, 2000, depending on
locale.
--
Matt Kruse http://www.JavascriptToolbox.com http://www.AjaxToolbox.com
In article <tR************ **@merlyn.demon .co.uk>, Dr John Stockton
says... If you allow an adaptive variety, you need to be reasonably sure that there are no unexpected cases that are misinterpreted, because your users may not notice that the switched form is not as expected.
Yes you are quite right. This is however an administrative application
as opposed to something that any member of the public may use and hence
training etc on the behaviour of the system will be available - and they
will know that the target date format is dd-mon-yyyy. Better IMHO to provide a set of radio-buttons and/or checkboxes to choose the current format, and to display by onChange or similar the date of Christmas in the currently selected format.
Do you go as far as allowing 25.XII.2005, 33/11/22, and 2005-W51-7, for example?
You could try reading the newsgroup FAQ; see below.
Thanks for the pointer.
--
jeremy
In article <YZ************ *******@twister .nyroc.rr.com>, Mick White
says... You said it is trivial: is it really?
Yes, but you can never be sure what the user will enter.
function convertDate(val ue){ var v=value.split(/[^\d]/); v[1]= ['jan','feb','ma r','apr','may', 'jun','jul','au g','sep','oct', 'nov','dec'][v[1]-1]; return v.join("-"); }
alert("3/12/05") // "3-dec-2005"
<input ... onchange="this. value=convertDa te(this.value)" >
Thanks, that's very helpful. You're aware that "3/12/2005" is interpreted as "March 12, 2005" in North America, are you not?
Noted ta.
--
jeremy
In article <dj*********@ne ws4.newsguy.com >, Matt Kruse says... Jeremy wrote: It has a standardised date format of dd/mm/yyyy and if you enter e.g. 3-12 it will switch it to 3/12/2005 Same applies for e.g. 3:12 etc Anyone know of some javascript which will do this for our HTML form fields? Using my generalized date functions at http://www.javascripttoolbox.com/date/ you could do something like this:
<input type="text" name="date" onChange="var d=parseDate(thi s.value);if(d== null){alert('Da te format not recognized!');} else{this.value =formatDate(d,' dd-MMM-yyyy)}">
With the default code, it would automatically recognize and parse dates in these formats: y-M-d MMM d, y MMM d,y y-MMM-d d-MMM-y MMM d M/d/y M-d-y M.d.y MMM-d M/d M-d d/M/y d-M-y d.M.y d-MMM d/M d-M
You could modify the parseDate function to easily parse more date formats.
OK that looks interesting too. You should of course be aware that some values entered will be ambiguous. 1/2/2000 can mean Jan 2, 2000 just as well as Feb 1, 2000, depending on locale.
Thanks for the reminder.
--
jeremy This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sune |
last post by:
I'm working on a system that requires alot of date handling, and i'm getting
pretty tired of doing custom calculating when modifying dates, so i hope
someone would be able to help me.
Is there any easy way to do re-calculating of dates? such as adding 2,11
or 36 months to a date, and have it automatically checking whether or not
it should increase months or year, and by how much?
Like, if i have to add 11 months to the date right now, i...
|
by: Tatiana Zadiraka |
last post by:
I use DB2 8.1 with FixPack 5. In command line for sql I get all DATE
columns only in MM-DD-YYYY format. Of course, DATE('20-12-2003') gives
me an error
SQL0181N The string representation of a datetime value is out of
range.
SQLSTATE=22007
My db config is:
Database territory = RU
|
by: DKode |
last post by:
I find myself writing repetitive functions for handling null values
from my DB like so:
Private Function SetDateNull(ByVal p_date As Object) As Date
If (TypeOf (p_date) Is System.DBNull) Then
p_date = Date.MinValue
End If
Return p_date
End Function
|
by: Dr John Stockton |
last post by:
For an all-numeric Gregorian date to be intrinsically unambiguous, it
must generally be of the form /\d{3,}\D+\d+\D+\d+/ ; and we've
discussed handling that.
But if the month is given in letters (in full, as a LTA, or as Roman
numerals) , then the date is unambiguous
if the value of the year field is greater than the greatest possible day
field value - in which case the year value is greater than the actual
day value - whatever...
|
by: JonathanParker |
last post by:
Another quick one!
Trying to search for records by both accounting period and by year in two seperate queries actioned by option buttons. I've sorted the formatting so it's in a UK format but I keep getting the same error
'(3122) you tried to execute a query that does not include the specific expression 'tblAccounting.Period=0406 And tblProduction.DepartmentID=1 ?And tblUtility.UtilityID=1' as part of an aggregate function.'
I can't...
| |
by: syntego |
last post by:
We commonly use triggers to log changes to our main tables to
historical log tables.
In the trigger, we create a concatenated string of the old values by
casting them as follows:
CAST(O.MYDATE AS CHAR(30))
When directly updating date fields in the main table, the logged value
gets saved in the format YYYY-MM-DD as expected.
|
by: bhavu10 |
last post by:
hi
i have created a form forreport with today, week month & year CMD
Button
but i think i wrote the code wrong for month and also it shows me only
records for this year whewe as i have 2006 records too code is written
in Event Procedure of Respective Cmd Button Can there be a problem in
TODAY'S Cmd Button code that it shows me only 2007 record PLEASE HELP.
Private Sub cmdMonth_Click()
|
by: bruce.dodds |
last post by:
Access seems to be handling a date string conversion inconsistently in
an append query.
The query converts a YYYYMM string into a date, using the following
function:
CDate(Right(,2) & "/1/" &
Left(,4))
I entered the string "200715" in a record to test an error condition.
|
by: ashore |
last post by:
Guys, the line below just returned "Dec 07" as the date for one month
back from today. Hardly life-threatening, but any thoughts?
<?php print date("M `y", mktime(0, 0, 0, date("m")-1, date("d"),
date("Y")));?>
AS
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |