Rism: focus() auf textfeld ohne Formularnamen?

Hallo,

ich möchte den focus auf ein textfeld legen, dass sich in einem Formular ohne das "name" attribut befindet. Wie spreche ich dieses Textfeld an?

Normalerweise ja so:
onload="self.focus(); document.formularname.textfeldname.focus()"

Aber was machen, wenn das Formular keinen namen hat?

  1. Hallo,

    ich möchte den focus auf ein textfeld legen, dass sich in einem Formular ohne das "name" attribut befindet. Wie spreche ich dieses Textfeld an?

    Normalerweise ja so:
    onload="self.focus(); document.formularname.textfeldname.focus()"

    Aber was machen, wenn das Formular keinen namen hat?

    Schande über mich. Ich habs gefunden: http://de.selfhtml.org/javascript/objekte/elements.htm

    Die Lösung:

    <body onload="document.forms[0].textfeldname.focus();">

    wobei "forms[0]" das erste formular auswählt.