Hallo,
ich hab ein kleines Formular bestehend aus einer Liste, einem Eingabe-Feld und einem submit-Button.
Ich möchte die Enter-Taste abfragen, um die Eingabe zu überprüfen und NUR gegebenenfalls das Formular abzuschicken.
Das Problem ist nur, dass das Formular IMMER abgeschickt wird, auch wenn meine Funktion aufgerufen wird. Ich hab keine Ahnung, wie ich das verhindern könnte.
Ich poste einfach mal den Quelltext, vielleicht kann mir dabei jemand helfen?
Naja, mit dem IE5x läufts schon, aber weder beim NC4.78 noch 6.21.
Gruß,
Knud
<HTML><HEAD>
<meta http-equiv="expires" content="0">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Geräteauswahl Ergoline Avantgarde</title>
<script language="Javascript">
var Netscape = 0;
var xfield = 0;
if(navigator.appName == "Netscape") Netscape = 1;
function TasteGedrueckt(Ereignis) {
if (Netscape == 1) {
// prüfen auf Enter-Taste und ob im Suchfeld, ob nur 1 in Liste, dann ausführen
ntaste = Ereignis.which;
if (ntaste == 13 && xfield == 1) {
if (document.main.Geraet.length == 1) {
// Wert aus Liste holen und ausführen
alert("NC sucks!");
return false;
}
}
}
}
if (Netscape == 1) {
document.onkeydown = TasteGedrueckt;
document.captureEvents(Event.KEYDOWN);
}
function klicked() {
// Doppelklick in der Auswahl (nur IE und NC 6.x)
alert("Doppelklick in der Liste");
}
function suche() {
// eingegebener Suchtext in Großbuchstaben
suchtext = document.main.suchfeld.value.toUpperCase();
if (suchtext != "") {
// text im kompletten Array suchen und Liste aktualisieren
fillSelectFromArrayFULL(document.main.Geraet,a_suche,suchtext)
} else {
// alte (gesicherte) Liste zurückspielen
j = 0;
for (i = 0; i < a_suche.length; i=i+2) {
document.main.Geraet.options[j] = new Option(a_suche[i]);
document.main.Geraet.options[j].value = a_suche[i+1];
j++;
}
}
}
function fillSelectFromArrayFULL(selectCtrl, itemArray, suchtext) {
// Liste löschen
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options[i] = null;
}
// neue Einträge hinzufügen
j = 0;
found = false;
for (i = 0; i < itemArray.length; i=i+2) {
stext = itemArray[i].toUpperCase();
if (stext.indexOf(suchtext)>=0){ //gefunden --> Eintrag wieder dazu
found = true;
selectCtrl.options[j] = new Option(itemArray[i]);
selectCtrl.options[j].value = itemArray[i+1];
j++;
}
}
if (found == false) { //nichts gefunden --> wieder Original zurückspielen
j = 0;
for (i = 0; i < itemArray.length; i=i+2) {
selectCtrl.options[j] = new Option(itemArray[i]);
selectCtrl.options[j].value = itemArray[i+1];
j++;
}
}
// ersten Eintrag selektieren
// selectCtrl.options[0].selected = true;
}
var a_suche;
function init() {
a_suche = new Array();
if (document.main) {
// Liste sichern
for(i=0;i<document.main.Geraet.length;++i) {
if (Netscape == 1) {
nelement = a_suche.push(document.main.Geraet.options[i].text);
nelement = a_suche.push(document.main.Geraet.options[i].value);
} else {
a_suche[a_suche.length] = document.main.Geraet.options[i].text;
a_suche[a_suche.length] = document.main.Geraet.options[i].value;
}
}
}
}
</script>
<script for="document" event="onkeydown()" language="JScript" type="text/jscript">
{
ntaste = window.event.keyCode;
if (ntaste == 13 && xfield == 1) {
if (document.main.Geraet.length == 1) {
// Wert aus Liste holen und ausführen
alert("IE sucks!");
return false;
}
}
}
</script>
</head><body background="/common/Ergoline_soft.jpg" bgproperties="fixed" onLoad="init();">
<basefont face="Arial">
<center><table border="0" cellpadding="0" cellspacing="0" width="80%">
<tr><td>
<form action="/cgi-bin/gauswahl.exe" method="GET" name="main" target=header>
<input type="hidden" name="pic" value="erlogo.gif">
<input type="hidden" name="T" value="Ergoline Avantgarde">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td align="center" width="20%"><font color="#000000"><b><img src="/bilder/avantgarde.jpg" width="129" height="81"></b></font></td>
<td align=center><font color="#000000" size="5">
<b>Ergoline Avantgarde auswählen</b>
</font><font color="#800080"><b></td></tr>
<tr><td align=center valign=center><font size="4"><strong>
Gerätetyp</strong></font><font size="3"></font></td>
<td align=center><select name="Geraet" size=6 onDblClick="klicked();">
<option selected>52111000 ERGOLINE 550 AVANTGARDE SUPER POWER R AUGE ROT
<OPTION>52111100 ERGOLINE 550 AVANTGARDE SUPER POWER R AUGE ROT KLIMA
<OPTION>52116000 ERGOLINE 550 AVANTGARDE SUPER POWER SR AUGE ROT
<OPTION>52116100 ERGOLINE 550 AVANTGARDE SUPER POWER SR AUGE ROT KLIMA
<OPTION>52121000 ERGOLINE 550 AVANTGARDE SUPER POWER R AUGE BLAU
<OPTION>52121100 ERGOLINE 550 AVANTGARDE SUPER POWER R AUGE BLAU KLIMA
<OPTION>52126000 ERGOLINE 550 AVANTGARDE SUPER POWER SR AUGE BLAU
<OPTION>52126100 ERGOLINE 550 AVANTGARDE SUPER POWER SR AUGE BLAU KLIMA
<OPTION>52211000 ERGOLINE 600 AVANTGARDE SUPER POWER R AUGE ROT
<OPTION>52211100 ERGOLINE 600 AVANTGARDE SUPER POWER R AUGE ROT KLIMA
<OPTION>52215000 ERGOLINE 600 AVANTGARDE TURBO POWER R AUGE ROT
<OPTION>52215100 ERGOLINE 600 AVANTGARDE TURBO POWER R AUGE ROT KLIMA
<OPTION>52216000 ERGOLINE 600 AVANTGARDE SUPER POWER SR AUGE ROT
<OPTION>52216100 ERGOLINE 600 AVANTGARDE SUPER POWER SR AUGE ROT KLIMA
<OPTION>52217000 ERGOLINE 600 AVANTGARDE TURBO POWER SR AUGE ROT
<OPTION>52217100 ERGOLINE 600 AVANTGARDE TURBO POWER SR AUGE ROT KLIMA
<OPTION>52221000 ERGOLINE 600 AVANTGARDE SUPER POWER R AUGE BLAU
<OPTION>52221100 ERGOLINE 600 AVANTGARDE SUPER POWER R AUGE BLAU KLIMA
<OPTION>52225000 ERGOLINE 600 AVANTGARDE TURBO POWER R AUGE BLAU
<OPTION>52225100 ERGOLINE 600 AVANTGARDE TURBO POWER R AUGE BLAU KLIMA
<OPTION>52226000 ERGOLINE 600 AVANTGARDE SUPER POWER SR AUGE BLAU
<OPTION>52226100 ERGOLINE 600 AVANTGARDE SUPER POWER SR AUGE BLAU KLIMA
<OPTION>52227000 ERGOLINE 600 AVANTGARDE TURBO POWER SR AUGE BLAU
<OPTION>52227100 ERGOLINE 600 AVANTGARDE TURBO POWER SR AUGE BLAU KLIMA
<OPTION>34519800 ZENTRALABLUFTSTUTZEN SCHWARZ MIT WARMLUFTRÜCKF. F. AVANTGARDE 550/600
<OPTION>34519900 ZENTRALABLUFTSTUTZEN SCHWARZ OHNE WARMLUFTRÜCKF. F. AVANTGARDE 550/600
</select></td>
</tr><tr><td> </td><td align=center valign=top><font size="3"><xxinput type=submit name="Speichern" value="Auswahl bestätigen"></font>
</td></tr></table>
Suchfeld: <input type=text name=suchfeld size=30 onkeyup="suche();" onFocus="xfield=1;" onBlur="xfield=0;">
</form></td><td valign=bottom align=left>
<form action="/html/GWahl_A.htm" method=get><input type=submit name="Zurück" value="Zurück"></form></td></tr></table>
<table border="0" cellpadding="0" cellspacing="0" width="80%">
<tr><td><img src="/bilder/Achtung.gif" align="right" hspace="0" width="99" height="84"></td>
<td>Bitte lesen Sie die <a href="/cgi-bin/trans.exe?PATH=EINL" target=main>Sicherheitshinweise zum gewählten Gerät!</a></td></tr>
</tr></table></center></body></html>