473,839 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

html form: date field auto-adjust

Dear scripters,

I am working on a HTML form in which a date must be entered of the form
'dd-mm-yyyy'. Now I'm looking for a script that, when the user switches to
another form field, changes e.g. 'ddmmyyyy' or 'dd-m-yy' to 'dd-mm-yyyy'.

I have searched the net using google, but only found validators that show
an error if an incorrect format is used. (and I can't write one on my own)

Does someone has such a script for me?

much thanks in advance!

Martin
Jul 23 '05 #1
36 11341
Lee
Martin Herrman said:

Dear scripters,

I am working on a HTML form in which a date must be entered of the form
'dd-mm-yyyy'. Now I'm looking for a script that, when the user switches to
another form field, changes e.g. 'ddmmyyyy' or 'dd-m-yy' to 'dd-mm-yyyy'.

I have searched the net using google, but only found validators that show
an error if an incorrect format is used. (and I can't write one on my own)


That can't be done, because the code can't guess whether 1122005 is January 12
or November 2. That's why you have to ask the user to correct it.

Jul 23 '05 #2
"Lee" <RE************ **@cox.net> wrote in message
news:d1******** *@drn.newsguy.c om...
Martin Herrman said:

Dear scripters,

I am working on a HTML form in which a date must be entered of the form
'dd-mm-yyyy'. Now I'm looking for a script that, when the user switches toanother form field, changes e.g. 'ddmmyyyy' or 'dd-m-yy' to 'dd-mm-yyyy'.

I have searched the net using google, but only found validators that show
an error if an incorrect format is used. (and I can't write one on my
own)
That can't be done, because the code can't guess whether 1122005 is January 12 or November 2. That's why you have to ask the user to correct it.


Unless you only reformat the entry with dashes if it has a length of 8.

<html>
<head>
<title>ddmmyyyy .htm</title>
<script type="text/javascript">
function format(that) {
var what = that.value;
if (what.length != 8) return;
that.value = what.substr(0,2 ) + "-" + what.substr(2,2 ) + "-" +
what.substr(4);
}
</script>
</head>
<body>
<form>
<input type="text" name="dmy" size="10" maxlength="10"
value="01122005 " onblur="format( this)">
</form>
</body>
</html>
Jul 23 '05 #3
Lee wrote on 15 mrt 2005 in comp.lang.javas cript:
Martin Herrman said:

Dear scripters,

I am working on a HTML form in which a date must be entered of the
form 'dd-mm-yyyy'. Now I'm looking for a script that, when the user
switches to another form field, changes e.g. 'ddmmyyyy' or 'dd-m-yy'
to 'dd-mm-yyyy'.

I have searched the net using google, but only found validators that
show an error if an incorrect format is used. (and I can't write one
on my own)


That can't be done, because the code can't guess whether 1122005 is
January 12 or November 2. That's why you have to ask the user to
correct it.


'ddmmyyyy' or 'dd-m-yy' to 'dd-mm-yyyy'.

Given these constraints and
the boundaries of the "current" century
it can be done.

function organize(x){
if (/^\d{8}$/.test(x))
x.value = x.replace(/(\d{2})(\d{2})( \d{4})/,'$1-$2-$3')
else if (/^\d{1,2}\d{1,2} \d{2}$/.test(x)) {
a = x.split('-')
x.value = two(a[0])+'-'+two(a[1])+
'-'+(+a[2]>30)?'19'+a[2]:'20'+a[2]
}
}

function two(x){
return (x<10)?'0'+x:x
}

...............

<input onblur='organiz e(this)'>

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #4
Evertjan. wrote on 15 mrt 2005 in comp.lang.javas cript:
'ddmmyyyy' or 'dd-m-yy' to 'dd-mm-yyyy'.

Given these constraints and
the boundaries of the "current" century
it can be done.

function organize(x){
if (/^\d{8}$/.test(x))
x.value = x.replace(/(\d{2})(\d{2})( \d{4})/,'$1-$2-$3')
else if (/^\d{1,2}\d{1,2} \d{2}$/.test(x)) {
else if (/^\d{1,2}-\d{1,2}-\d{2}$/.test(x)) {
a = x.split('-')
x.value = two(a[0])+'-'+two(a[1])+
'-'+(+a[2]>30)?'19'+a[2]:'20'+a[2]
}
}

function two(x){
return (x<10)?'0'+x:x
}


--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #5
In article <Xn************ ********@194.10 9.133.29>,
ex************* *@interxnl.net says...
Lee wrote on 15 mrt 2005 in comp.lang.javas cript:
Martin Herrman said:

Dear scripters,

I am working on a HTML form in which a date must be entered of the
form 'dd-mm-yyyy'. Now I'm looking for a script that, when the user
switches to another form field, changes e.g. 'ddmmyyyy' or 'dd-m-yy'
to 'dd-mm-yyyy'.

Instead of using a textbox, maybe you could try dynamic listboxes
instead. That way, when the month listbox is clicked, the appropriate
amount of days are filled in the days listbox.

This way, you wouldn't have to worry if they put in a bad character or
not.

Jul 23 '05 #6
Lee
Evertjan. said:

Lee wrote on 15 mrt 2005 in comp.lang.javas cript:
Martin Herrman said:

Dear scripters,

I am working on a HTML form in which a date must be entered of the
form 'dd-mm-yyyy'. Now I'm looking for a script that, when the user
switches to another form field, changes e.g. 'ddmmyyyy' or 'dd-m-yy'
to 'dd-mm-yyyy'.

I have searched the net using google, but only found validators that
show an error if an incorrect format is used. (and I can't write one
on my own)


That can't be done, because the code can't guess whether 1122005 is
January 12 or November 2. That's why you have to ask the user to
correct it.


'ddmmyyyy' or 'dd-m-yy' to 'dd-mm-yyyy'.

Given these constraints and
the boundaries of the "current" century
it can be done.


But you can't assume those constraints.

Jul 23 '05 #7
"Lee" <RE************ **@cox.net> wrote in message
news:d1******** *@drn.newsguy.c om...
Martin Herrman said:

Dear scripters,

I am working on a HTML form in which a date must be entered of the form
'dd-mm-yyyy'. Now I'm looking for a script that, when the user switches toanother form field, changes e.g. 'ddmmyyyy' or 'dd-m-yy' to 'dd-mm-yyyy'.

I have searched the net using google, but only found validators that show
an error if an incorrect format is used. (and I can't write one on my
own)
That can't be done, because the code can't guess whether 1122005 is January 12 or November 2. That's why you have to ask the user to correct it.


"... e.g. 'ddmmyyyy' or 'dd-m-yy' to 'dd-mm-yyyy'." doesn't include
'd-mm-yyy';
therefore, '1122005' is November 2, 2005.

Unless the examples ("e.g.") were not definitive.

Jul 23 '05 #8
Lee wrote on 15 mrt 2005 in comp.lang.javas cript:
'ddmmyyyy' or 'dd-m-yy' to 'dd-mm-yyyy'.

Given these constraints and
the boundaries of the "current" century
it can be done.


But you can't assume those constraints.


They are given by the OP.

Why improving on a reasonable request,
instead of showing the asked code?
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #9
McKirahan wrote:
[...]

"... e.g. 'ddmmyyyy' or 'dd-m-yy' to 'dd-mm-yyyy'." doesn't include
'd-mm-yyy';
therefore, '1122005' is November 2, 2005.


Based on the suggested format, I make it 1 December 2005, or it
may be 11 February 2005.

Or does ddmmyyyy really mean mmddyyyy?

--
Zif
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4621
by: Kevin Lyons | last post by:
Hello, I am trying to get all of my form elements passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html to the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing name, email, countries, cities, products, courses, etc. The others display as they should on the subsequent page,
3
4984
by: williamc | last post by:
Somebody asked me if it would be possible to add auto-advance to a web form where there are a lot of repetitive 5 character fields. I took a look around the web and found a script, which appears to work in the couple of browsers I tried it in. However, when I look at the script it appears to have the wrong number of brackets. Then when I changed the script to the way I thought it should be, it still worked! I'm totally rusty on...
4
4140
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT the NO radio button, once I do that it will not work. Any help would be greatly appreciated. Mitch
15
4786
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update button will verify the information that has been entered and updates the data base if the data is correct. Update will throw an exception if the data is not validate based on some given rules. I also have a custom error handling page to show the...
1
1481
by: rgdwar1 | last post by:
Hello, I have two issues I need help with: I have a Data Entry form called Frm_Entry (with a corresponding table) with the following fields: Date Assigned (Date) Date Processed (Date) Date Submitted (Date) MS-Company (Text) Client (Text) Reimbursement Amount
1
2618
by: eunever32 | last post by:
Hi I have a struts (1.1) form <html:form <html:text <html:text ...
14
4268
by: jcage | last post by:
Is there any tutorials online for sending email through forms? I can send an email as well as write to my MySQL database from home with the following code but not at work. I think there might be something I'm missing header-wise that keeps me from making this work on my work system. I'm using Apache 1.3, PHP 4.1 (best the IT guys could do though I'm using 5.x at home), and MySQL as the database. Thanks VERY much for any help or...
2
6990
by: rlamber | last post by:
Hello, I have 2 subforms in a Main form, one links fine, the other doesn't. I am trying to link them both to a "tracking ID" on the main form. The Tracking ID is a text field that is a combination of an auto-number and an Alpha expression. The subform that links fine is a comments form (continuous form with just date field and memo box) and the subform that won't link is a larger, more detailed form where I would like to add more than one...
7
3345
by: bleachie | last post by:
Hey, I just need some help, my form seems to not send me all of the 'guestNames' and 'guestEmails' forms. i use this function to add more guestnames and guestemail fields based on the number of guests added. form.php function createGuestNameAndEmailElements() {
2
2303
by: MNNovice | last post by:
I am working on a database on my CD collection using Access 2003. Some of the table structures are given below. Table 1 tblMusicCategory Field 1: MusicCategoryID - Auto Number (PK) Field 2: MusicCategory - text Field 3: MusicCategoryAbbv - text Table 2 tblArtists Field 1 ArtistID - Auto Number (PK)
0
9855
marktang
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...
0
9697
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,...
1
10649
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,...
0
10295
tracyyun
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...
0
9426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7829
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
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...
2
4064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.