Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Javascript] Feld mit Focus ermitteln

Empfohlene Antworten

Veröffentlicht

Hallo,

wie kann ich den Feldnamen des Feldes ermitteln, auf dem der focus() aktuell ist? Ich möchte dem Feld (mit focus) einen Wert zuweisen.

Hmmm.

So auf Anhieb kenne ich keine Funktion, um zu prüfen, welches Feld den Fokus hat oder ob ein Feld den Fokus hat.

Du könntest aber bei jedem Feld einbauen, dass beim Event "onFocus" eine Variable mit dem Namen des jeweiligen Feldes gefüllt wird.

Später kannst du dann mit 'eval' den Namen auswerten und das Feld mit einem Wert bestücken.

Ich versuch's mal zu skizzieren:

<script type="text/javascript">

<!--

   var focusedField = "";


   function setValueOfFocusedField (val) {

      eval ("document.forms.myForm." + focusedField + ".value = '" + val + "';");

   }

//-->

</script>

<form name="myForm">

   <input type="text" name="feld1" onFocus="focusedField='feld1'"><br>

   <input type="text" name="feld2" onFocus="focusedField='feld2'"><br>

   <input type="text" name="feld3" onFocus="focusedField='feld3'"><br>

   ...

</form>

Ich kann mir aber vorstellen, dass es auch eine andere, bessere Möglichkeit gibt. Aber wenn du nichts Besseres findest, sollte dies auch gehen.

ich kenn das so weit nur für den IE.

nennt sich

document.activeElement

Bsp:

@see http://www.styleassistant.de/tips/beispiel69.htm

aber wie das mit Opera o. Mozilla FireFox geht,... kA

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.