Menu
Hello,
I got a free script on date format for forms but it’s much more complicated than I need. It displays three different date formats when I need only one.
MM/DD/YYYY is all I need. Could someone possibly help me edit this script to work for me, thanks!
[url]http://javascript.internet.com/forms/format-date.html
PS – I tried to put the code in this post but it was to big.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>
<script type="text/javascript">
Date.prototype.toDateString = function () {return isNaN (this) ? 'NaN' : [this.getMonth() < 9 ? '0' + (this.getMonth() + 1) : this.getMonth() + 1, this.getDate() < 10 ? '0' + this.getDate() : this.getDate(), this.getFullYear()].join ('/')}
</script>
</head>
<body>
<div>
<label>Date<input name="date" onchange="this.value = new Date (this.value).toDateString()" type="text"></label>
</body>
</html>
<i>
</i><html>
<head>
<script language="Javascript">
<!--
function showdate()
{
var today = new Date()
var month = today.getMonth() + 1
var day = today.getDate()
var year = today.getFullYear()
var s = "/"
document.date.forms.value = month + s + day + s + year
}
//-->
</script>
</head>
<body onload="showdate()">
<form name="date">
<input type=text size=11 name="forms">
</form>
</body>
</html>
[CODE]
<asp:TextBox id=txtSingleDOB runat="server" Width="100%" Text='<%# this.Profile.Customer.DateOfBirth == DateTime.MinValue ? "" : this.Profile.Customer.DateOfBirth.ToString("d") %>' MaxLength="10">
</asp:TextBox>
[/CODE]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>
<script type="text/javascript">
Date.prototype.toDateString = function () {return isNaN (this) ? 'NaN' : [this.getMonth() < 9 ? '0' + (this.getMonth() + 1) : this.getMonth() + 1, this.getDate() < 10 ? '0' + this.getDate() : this.getDate(), this.getFullYear()].join ('/')}
</script>
</head>
<body>
<div>
<label>Date<input name="date" onchange="this.value = new Date (this.value).toDateString()" type="text"></label>
</body>
</html>
[/QUOTE]
<i>
</i><html>
<head>
<script language="Javascript">
<!--
function showdate(date)
{
var today = new Date();
var month = today.getMonth() + 1;
var day = today.getDate();
var year = today.getFullYear();
var s = "/";
document.getElementById('txtSingleDOB').value = month + s + day + s + year;
}
//-->
</script>
</head>
<body onload="showdate()">
</body>
</html>
It'll do that if you type in something that the JavaScript interpreter doesn't recognize as a date. Type more carefully and give it another go.[/QUOTE]
<i>
</i>
<html>
<head>
<script language="Javascript">
<!--
function inputDOB(dob)
{
var DOBlength=dob.length;
var month = dob.charAt(0) + dob.charAt(1);
var day = dob.charAt(2) + dob.charAt(3);
var year = dob.charAt(4) + dob.charAt(5) dob.charAt(6) + dob.charAt(7);
var s ="/";
if (DOBlength != 8)
{
alert('Your DOB must be entered in as 8 consecutive numbers in the format mmddyyyy');
}
else
{
document.getElementById('txtSingleDOB').value = month + s + day + s + year;
}
}
//-->
</script>
</head>
<body>
DOB:
<input name="mydate" id="mydate" value="" type="text" size="8">
<input type="button" name="dobsubmit" value="Submit" onclick="inputDOB(document.getElementById('mydate').value)">
</body>
</html>
[CODE]
<script language="JavaScript" type="text/javascript">
<!--
// The format is specified as a string
// and passed to the function 'f20_FormatNumber()' on the onkeyup event of a text box
// There can be any number of applications on a page each with a unique format
// All variable, function etc. names are prefixed with 'f20_' to minimise conflicts with other JavaScripts
// Customising Variables
var f20_TypingColor='blue';
var f20_CompleteColor='black';
var f20_WarningColor='RED';
// Functional Code
// NO NEED to Change
var f20_Temp,f20_Lgth;
var f20_re=/D/g;
var f20_re1=/~/g;
function f20_FormatNumber(f20_obj,f20_tem){
f20_obj.style.color=f20_CompleteColor;
f20_re = /D/g;
f20_obj.value=f20_obj.value.replace(f20_re,'');
f20_Temp=f20_tem;
for (f20_0=0;f20_0<f20_obj.value.length;f20_0++){
f20_Lgth=f20_Temp.indexOf('~');
f20_Temp=f20_Temp.replace('~',f20_obj.value.charAt(f20_0));
}
if (f20_obj.value.length>0&&(f20_Lgth<0||f20_obj.value.length==f20_tem.match(f20_re1).length)){
f20_obj.value=f20_Temp.substring(0,f20_tem.length);
f20_obj.style.color=f20_CompleteColor;
}
if (f20_Lgth>=0&&f20_obj.value.length>0){
f20_obj.value=f20_Temp.substring(0,f20_Lgth+1);
}
f20_obj.lgth=f20_tem.length;
}
//-->
</script>
<asp:TextBox id=txtSingleHomePhone runat="server" Width="100%" Text="<%# this.Profile.Customer.HomePhone %>" MaxLength="14" onkeyup="javascript:f20_FormatNumber(this,'(~~~) ~~~-~~~~');">
</asp:TextBox>
[/CODE]
Is it possible to format it either as it's being typed in or on tab?[/QUOTE]
<i>
</i><html>
<head>
<script type="text/javascript">
<!--
//This function was written by Konithomimo to help properly format any date that is entered in as an 8 number string. It has not yet been adapted to check for anything besides numbers, or to check if the numbers entered will give an actual date, but can easily be adapted to do so. If you decide to use this script then please leave in these comments.
//This script has been edited to remove any input besides integers.
function inputDOB(dob)
{
var DOBlength=dob.length;
var month = dob.charAt(0) + dob.charAt(1);
var day = dob.charAt(2) + dob.charAt(3);
var year = dob.charAt(4) + dob.charAt(5) + dob.charAt(6) + dob.charAt(7);
var s ="/";
var m = eval(month);
var d = eval(day);
var y = eval(year);
if (DOBlength != 8)
{
alert('Your DOB must be entered in as 8 consecutive numbers in the format mmddyyyy');
}
if ((m < 1)||(y < 1900)||(d < 1)||(d > 31)||(m >12))
{
alert('You have entered in an invalid value for your month, day, or year. Your birth month must be 01-12, your birth day must be 01-31, and your birth year must be 1900 or later.');
}
else
{
document.getElementById('txtSingleDOB').value = month + s + day + s + year;
}
}
//-->
</script>
</head>
<body>
DOB(mmddyyyy):
<asp:TextBox id=txtSingleDOB runat="server" Width="100%" Text='<%# this.Profile.Customer.DateOfBirth == DateTime.MinValue ? "" : this.Profile.Customer.DateOfBirth.ToString("d") %>' MaxLength="10" onkeyup="this.value=this.value.replace(/D/,'')" onblur="inputDOB(document.getElementById('txtSingleDOB').value)"></asp:TextBox>
</body>
</html>
This is what I'm using for the phone numbers and it works great[/QUOTE]
0.1.9 — BETA 5.10