I am trying to set date format as following
- Whenever user enters 2 numbers
automatically one sign like / is created
- Whenever user enters another 2 numbers
automatically one sign like / is created again
<script
language="javascript"
type ="text/javascript">
function formatDate(obj) {
//04/04/2011 PP
var v_date = obj.value
var numCount = v_date.length;
if ((event.keyCode >= 48 &&
event.keyCode <= 57)) {
if (numCount == 2) {
obj.value = v_date + "/"
}
else if
(numCount == 5) {
obj.value = v_date + "/"
}
}
else {
event.keyCode = 0;
}
}
</script>
<input
type="text"
id="txtfrmdt"
onkeypress="javascript:formatDate(this);"
/>