ChrisB: document.getElementById("myInputfield").focus = true; geht nicht

Beitrag lesen

Hi,

ich möchte den cursor per Javascript in ein bestimmtes Formularfeld setzen.

Ich habe dazu:
document.getElementById("myInputfield").focus = true;

Damit gibst du dem Feld eine neue Eigenschaft namens focus mit dem Inhalt true.

Das klapt aber nicht.

Doch, das klappt.
Es ist aber nicht das, was du willst.
Du möchtest vermutlich die Methode focus des Formularelements aufrufen.

Kann ich einem Formularfeld den focus geben _ohne_ dass das Formular einen Namen hat?

Wie du auf das Feld zugreifst, ist vollkommen egal.

MfG ChrisB

--
Light travels faster than sound - that's why most people appear bright until you hear them speak.