-
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
:D
-
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.
-
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
-
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.