Zum Inhalt springen

Eingabe durch JavaScript überprüfen und transitional valide?

Erstellt am 3. Juli 2007 · 6 Antworten · letzte Antwort am 4. Juli 2007

Tags: Frage

linajoy ·

Hallo, weiß jemand wie ich die Eingabe in ein Formular überprüfen und trotzdem valide arbeiten kann?

Es wird immer vorausgesetzt, das das Formular das atribute "name" erhält, dieses gibt es aber im transitionalen XHTML nicht.

<form action="kontakt.php"  method="post" name="Formular"  onsubmit="return chkFormular()">

damit dann folgendes funktioniert:

function chkFormular () {
  if (document.Formular.name.value == "") {
    alert("Bitte Ihren Namen eingeben!");
    document.Formular.User.focus();
    return false;
  }
fuss ·

Olla!

Es wird immer vorausgesetzt, das das Formular das atribute "name" erhält, dieses gibt es aber im transitionalen XHTML nicht.

Das ist teils richtig:
name gibt es als Attribut nicht bei XHTML, es wird aber nicht vorausgesetzt, dass das Formular das Attribut name erhält, weil:

"The id attribute replaces the name attribute"

siehe:
http://www.w3schools.com/xhtml/xhtml_syntax.asp

gruss, fuss

jenses ·
linajoy schrieb

Es wird immer vorausgesetzt, das das Formular das atribute "name" erhält, dieses gibt es aber im transitionalen XHTML nicht.

Wie kommst du darauf?
Natürlich ist das name-Attribut valide XHTML transitional.
Siehe hier: SelfHTML - Form

Dein Javascript-Schnipsel steckt allerdings auch voller Ungereimtheiten.
Versuche es mal hiermit:

<script language="JavaScript" type="text/JavaScript">
        /*<![CDATA[*/
<!--


function check(theForm)
{

if(theForm.vorname.value == "") {
    alert("Bitte geben Sie Ihren Vornamen an!");
    theForm.vorname.focus();
    return false;
}
    return true;
}


// -->
        /*]]>*/
</script>



<form action="kontakt.php" name="Formular" onSubmit="return check(this)" method="post" enctype="multipart/form-data">
fuss schrieb

Das ist teils richtig:
name gibt es als Attribut nicht bei XHTML, es wird aber nicht vorausgesetzt, dass das Formular das Attribut name erhält, weil:

"The id attribute replaces the name attribute"

siehe:
http://www.w3schools.com/xhtml/xhtml_syntax.asp

Auch das stimmt nicht so ganz, die Aussage betrifft nicht das Form-Tag:

HTML 4.01 defines a name attribute for the elements a, applet, frame, iframe, img, and map. In XHTML the name attribute is deprecated. Use id instead.

Wenn schon zitieren, dann richtig und vollständig.

fuss ·

Auch das stimmt nicht so ganz, die Aussage betrifft nicht das Form-Tag:

Auch teils nicht richtig: 😉
bei XHTML transitional ist name im form tag erlaubt (so wie von lina gewünscht)
bei XHTML strict hingegen ist name nicht erlaubt.

Ob man nun transitional oder strict nimmt, jeder nach seiner Fasson halt 😉
gruss, fuss

jenses ·
fuss schrieb

Auch teils nicht richtig: 😉
bei XHTML transitional ist name im form tag erlaubt (so wie von lina gewünscht)
bei XHTML strict hingegen ist name nicht erlaubt.

Da hast du natürlich recht,
nur: nach XHTML strict wurde nicht gefragt, oder? 😉

linajoy ·

prima, danke das Beispiel von jenses klappt prima. Mein Beispielt stammte übrigens quasi 1 zu 1 von SelftHTML.

Grüße Lina