Guten Morgen,
da ich das "Keyboard" standardmäßig ausgeblendet habe (kein Touchdisplay), und auch mehr als ein Eingabefeld pro Seite haben könnte habe ich nachfolgendes Programm geschrieben.
Problem:
Wenn ich in den Funktionen die "id" des Textfeldes (input) fest eingebe, dann funktioniert alles. Wenn ich die "id" als Variable übergebe kommt die Fehlermeldung im debugger "ReferenceError: idtextfeld is not defined"
Anbei der Code.... vielleicht fällt etwas auf.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 2"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">  
  
<head>  
   <title>my Keyboardtest</title>  
   <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />  
   <script type="text/javascript" src="keyboard.js"></script>  
   <style type="text/css">  
      #textfeld {  
          width:122px;  
          height:25px;  
          border:1px solid #000;  
          font:16px/20px Arial;  
          color:#000;  
          text-align: right;  
          padding:2px;  
          margin:0 0 20px 0;  
        }  
  
      .tasten {  
          width:30px;  
          height:30px;  
          font:bold 16px/20px Verdana;  
          color:#000;  
          text-align: center;  
          background-color: #ccc;  
          cursor: default;  
          margin:2px;  
        }  
   </style>  
  
<script type="text/javascript">  
function keyboard()  
{ open_keyboard('textfeld', 'keyboard'); }  
  
</script>  
</head>  
  
<body>  
  
<input type="text" id="textfeld" maxlength="10"><img src="keyboard.jpeg" alt="Tastatur" width="25" height="25" onclick="keyboard();"/>  
<div id="keyboard"></div>  
  
</body>  
</html>  
und hier das Javascript
  
function writeText(taste, idtextfeld)  
{ document.getElementById(idtextfeld).value = document.getElementById(idtextfeld).value + document.getElementById(taste).value; }  
  
function backspace(taste, idtextfeld)  
{ document.getElementById(idtextfeld).value = document.getElementById(idtextfeld).value.substr(0, document.getElementById(idtextfeld).value.length - 1); }  
  
function negativText(taste, idtextfeld)  
{ if ( document.getElementById(idtextfeld).value == '' ) return; document.getElementById(idtextfeld).value = document.getElementById(idtextfeld).value *(-1); }  
  
function loeschen(taste, idtextfeld)  
{ document.getElementById(idtextfeld).value = ''; }  
  
function komma(taste, idtextfeld)  
{  
	if (document.getElementById(idtextfeld).value.length < 1)  
	{ document.getElementById(idtextfeld).value = '0.'; return; }  
  
	if (document.getElementById(idtextfeld).value.indexOf('.') < 0)  
	{ document.getElementById(idtextfeld).value = document.getElementById(idtextfeld).value + '.'; }  
}  
  
function open_keyboard(idtextfeld, idkeyboard)  
{  
	if (document.getElementById(idkeyboard).innerHTML == '')  
	{  
	document.getElementById(idkeyboard).innerHTML = "<table id=table border=\"1\" style=border:2px solid #000;><tr><td><input type=\"button\" id=\"t1\" class=\"tasten\" value=\"1\" onclick=\"writeText(this.id, idtextfeld);\"><\/td><td><input type=\"button\" id=\"t2\" class=\"tasten\" value=\"2\" onclick=\"writeText(this.id, idtextfeld);\"><\/td><td><input type=\"button\" id=\"t3\" class=\"tasten\" value=\"3\" onclick=\"writeText(this.id, idtextfeld);\"><\/td><\/tr><td><input type=\"button\" id=\"t4\" class=\"tasten\" value=\"4\" onclick=\"writeText(this.id, idtextfeld);\"><\/td><td><input type=\"button\" id=\"t5\" class=\"tasten\" value=\"5\" onclick=\"writeText(this.id, idtextfeld);\"><\/td><td><input type=\"button\" id=\"t6\" class=\"tasten\" value=\"6\" onclick=\"writeText(this.id, idtextfeld);\"><\/td></tr><td><input type=\"button\" id=\"t7\" class=\"tasten\" value=\"7\" onclick=\"writeText(this.id, idtextfeld);\"><\/td><td><input type=\"button\" id=\"t8\" class=\"tasten\" value=\"8\" onclick=\"writeText(this.id, idtextfeld);\"><\/td><td><input type=\"button\" id=\"t9\" class=\"tasten\" value=\"9\" onclick=\"writeText(this.id, idtextfeld);\"><\/td><\/tr><tr><td><input type=\"button\" id=\"t10\" class=\"tasten\" value=\"±\" onclick=\"negativText();\"><\/td><td><input type=\"button\" id=\"t11\" class=\"tasten\" value=\"0\" onclick=\"writeText(this.id, idtextfeld);\"><td><input type=\"button\" id=\"t12\" class=\"tasten\" value=\".\" onclick=\"komma(this.id, idtextfeld);\"><\/td><\/td><\/tr>    <tr><td><input type=\"button\" id=\"t13\" class=\"tasten\" value=\"clr\" onclick=\"loeschen(this.id, idtextfeld);\"><\/td><td><input type=\"button\" id=\"t14\" class=\"tasten\" value=\"\"><\/td><td><input type=\"button\" id=\"t15\" class=\"tasten\" value=\"<-\" onclick=\"backspace(this.id, idtextfeld);\"><\/td><\/tr><\/table>";  
  
	}  
	else  
	{ document.getElementById(idkeyboard).innerHTML = ''; }  
}  
Bin für jeden Tip oder aber auch Verbesserung dankbar.
Gruß
    roger
 nicht angemeldet
 nicht angemeldet Matthias Apsel
 Matthias Apsel