javascript - How to get if a player presses the TAB key in a forum -


so, i'm making school project (a game of sorts), , mail address school. record mail address in database , want add little feature. if 'player' presses tab key in third forum box, fourth gets automatically filled number entered in third box (student number) @... after it.

how can fire event when tab key pressed in third box? have:

<script>       function automail() {         if (event.keycode == 9) {           console.log("mail automatisch ingevuld!");           event.preventdefault();         }       } </script>  <td style="color: white; font-weight: bold;" onkeypress="automail()">leerlingnummer:</td> 

this doesn't work, however. has idea?

(btw: have onkeypress event somewhere else in site, wich work. can't figure out why 1 doesn't...)

first of need pass event function this

 <td style="color: white; font-weight: bold;" onkeypress="automail(event)">leerlingnummer:</td> 

then can use variable take key, put alert know key number , me tab keynumber 0 try following code

function automail(e) {         key = (document.all) ? e.keycode : e.which;                     if (key == 0) {            alert("mail automatisch ingevuld!");              // code....                    }     } 

if isn't keynumber 0, can add alert variable "key"


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -