|
-
Jan 17th, 2003, 07:45 AM
#1
Thread Starter
Addicted Member
Date TextBox
Hi there, I have got a textbox on my web page that contains a date, i want to be able to change the date when different keys are pressed, for example if the user presses 't' then the date changes to the current date.
The initial date is in this format dd/mm/yy.
How do you take the value from th textbox and convert it to a date in javascript..
Thanks
Rohan
-
Jan 17th, 2003, 08:05 AM
#2
Code:
<script language="javascript">
var whatever = new Date();
</script>
<form name=simpleform>
<input type=text value="13/9/2002" name=somedate>
<input type=button onClick="javascript:document.simpleform.somedate.value=whatever;">
</form>
Manipulate "whatever" however it is required by you.
-
Jan 17th, 2003, 09:06 AM
#3
Thread Starter
Addicted Member
hi there, thanks for the reply, when i update the textbox the date changes format,
from
17/01/2003
to
Thu Jan 1 00:00:00 UTC 2004
is there a way of changing it back
Thanks
Rohan
-
Jan 17th, 2003, 10:17 AM
#4
Thread Starter
Addicted Member
Problem with code
<html>
<head>
<title>Test</title>
<script>
function addZero(vNumber)
{
return((vNumber < 10) ? "0" : "") + vNumber
}
function change(txtDate)
{
key = window.event.keyCode;
result = new Date(txtDate.value);
switch(key)
{
case 34:
result.setMonth(result.getMonth() - 1);
break;
case 33:
result.setMonth(result.getMonth() + 1);
break;
case 84:
result = new Date();
break;
case 40:
result.setDate(result.getDate() - 1);
break;
case 38:
result.setDate(result.getDate() + 1);
break;
}
var output = addZero(result.getDate()) + '/' + addZero(result.getMonth()+1) + '/' + result.getFullYear();
txtDate.value = output;
return false;
}
</script>
</head>
<body>
<form method="POST" action="--WEBBOT-SELF--">
<p><input type="text" name="T1" size="36" onkeydown="return change(this);" value="01/01/2003"></p>
</form>
</body>
</html>
there is a problem with the output date, it looks ok but when it is put back in the textbox the next keypress causes an invalid date.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|