peterS.: Datum in ein Formfeld

Beitrag lesen

gruss,

... und hier gibt es noch mehr zum rumspielen,
       denn es ging ja auch um formatierungen:

bsp.:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
<title>document.lastModified</title>
<script language="JavaScript" type="text/javascript">
<!--
function datum(part01,part02,part03,ruler)
 {var myDate = new Date(Date.parse(document.lastModified));
  if (part01 == "DD") {part01 = myDate.getDay()+"";if (part01.length == 1) {part01 = "0" + part01;}}
  if (part01 == "MM") {part01 = myDate.getMonth()+"";if (part01.length == 1) {part01 = "0" + part01;}}
  if (part01 == "YY") {part01 = myDate.getYear()+"";if (part01.length > 2) {part01 = part01.charAt(part01.length-2) + part01.charAt(part01.length-1);}}
  if (part01 == "YYYY") {part01 = myDate.getYear()+"";if (parseInt(part01) < 1000) {part01 = (parseInt(part01)+1900)+"";}}
  if (part02 == "DD") {part02 = myDate.getDay()+"";if (part02.length == 1) {part02 = "0" + part02;}}
  if (part02 == "MM") {part02 = myDate.getMonth()+"";if (part02.length == 1) {part02 = "0" + part02;}}
  if (part02 == "YY") {part02 = myDate.getYear()+"";if (part02.length > 2) {part02 = part02.charAt(part02.length-2) + part02.charAt(part02.length-1);}}
  if (part02 == "YYYY") {part02 = myDate.getYear()+"";if (parseInt(part02) < 1000) {part02 = (parseInt(part02)+1900)+"";}}
  if (part03 == "DD") {part03 = myDate.getDay()+"";if (part03.length == 1) {part03 = "0" + part03;}}
  if (part03 == "MM") {part03 = myDate.getMonth()+"";if (part03.length == 1) {part03 = "0" + part03;}}
  if (part03 == "YY") {part03 = myDate.getYear()+"";if (part03.length > 2) {part03 = part03.charAt(part03.length-2) + part03.charAt(part03.length-1);}}
  if (part03 == "YYYY") {part03 = myDate.getYear()+"";if (parseInt(part03) < 1000) {part03 = (parseInt(part03)+1900)+"";}}
  mydate = new String();myDate = part01 + ruler + part02 + ruler + part03;
  return myDate;
 }
function insertDate()
 {self.document.forms["myForm"].elements["Datum"].value = self.datum("DD","MM","YY",".");}
//-->
</script>
</head>

<body onload="self.insertDate()">
<table cols="1" rows="1" width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
 <td align="center" valign="middle">

<form name="myForm">
 <table cols="1" rows="1" width="50" cellspacing="0" cellpadding="10" border="1">
 <tr>
  <td align="left" valign="top" nowrap="nowrap">
  Datum: (TT.MM.JJ)
  </td>
  <td align="left" valign="top" nowrap="nowrap">
 <!--eine einfache moeglichkeit-->
 <!--<input type="text" name="Datum" size="20" maxlength="20" onfocus="this.value=document.lastModified">-->

<!--auf onload  mit funktionsaufruf-->
 <!--auf onfocus mit funktionsaufruf - ACHTUNG: andere parameter !!-->
  <input type="text" name="Datum" size="20" maxlength="20" onfocus="this.value=self.datum('DD','MM','YYYY','/')">
  </td>
 </tr>
 </table>
 </form>

</td>
</tr>
</table>
</body>

</html>

viel spass - by(t)e by(t)e - peterS. - pseliger@gmx.net